I have a ClassA
with 10 fields and have the following list populated with 100 records.
List<ClassA> abc = new List<ClassA>();
I have another class ClassB
with 12 fields where 10 fields are same as Class and 2 extra fields which are lets say harcoded ,viz field11
and field12
. Property names of ClassA and ClassB are same.
I have tried looping ClassA
list and build ClassB
object inside the loop and keep adding to the list of ClassB
with 2 extra columns.
But is there any better way to achieve this?
2
Answers
Yes, you can use auto mapping libraries. Like AutoMapper or Mapster
They can map your entities by properties naming convention. And also you can setup specific rules for each mapping.
Please look for documentation in above links.
you can use select :