© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
3 replies
zikalol

❔ ❔ Better way to map object

Hello guys, i have an object called Room and it have building,floor,zone data

Data im getting
class room {
buildingProp1
buildingProp2
FloorProp1
ZoneProp1
Roomprop3
Roomprop4
}
//i want to generate multiple classes like that

//building
class row1 {
buildingprop1
buildingprop2
FloorProp1 = null
ZoneProp1 = null
Roomprop3 = null
Roomprop4 =  null
}
//Floor
class row2{
buildingprop1
buildingprop2
FloorProp1
ZoneProp1 = null
Roomprop3 = null
Roomprop4 =  null
}
//Zone
class row3{
buildingprop1
buildingprop2
FloorProp1
ZoneProp1
Roomprop3 = null
Roomprop4 =  null
}
//room
class row4 {
buildingProp1
buildingProp2
FloorProp1
ZoneProp1
Roomprop3
Roomprop4
}
Data im getting
class room {
buildingProp1
buildingProp2
FloorProp1
ZoneProp1
Roomprop3
Roomprop4
}
//i want to generate multiple classes like that

//building
class row1 {
buildingprop1
buildingprop2
FloorProp1 = null
ZoneProp1 = null
Roomprop3 = null
Roomprop4 =  null
}
//Floor
class row2{
buildingprop1
buildingprop2
FloorProp1
ZoneProp1 = null
Roomprop3 = null
Roomprop4 =  null
}
//Zone
class row3{
buildingprop1
buildingprop2
FloorProp1
ZoneProp1
Roomprop3 = null
Roomprop4 =  null
}
//room
class row4 {
buildingProp1
buildingProp2
FloorProp1
ZoneProp1
Roomprop3
Roomprop4
}

PS: ofc i rows 4 inherits row 3 and row 3 inherits row 2 etc..
i have done it with automapper I autoMap all rows to the row4 class then i aggregate the list to a tuple that contains lists of row 1 row 2 row 3 then i map them again to row4 class then i add them to the original list.

Is there any better way to do it ? i have used aggregate to just generate all data with one loop
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

AutoMapper - map object from source to destionation's list of objects.
C#CC# / help
4y ago
better way to do this?
C#CC# / help
3y ago
Compare Strings better way.
C#CC# / help
13mo ago