I have below class mechanicalData like
public class MechanicalData
{
public List<LibraryLighting> InternalLoadsLighting { get; set; }
public List<LibraryEquipment> InternalLoadsEquipment { get; set; }
}
and then i am mapping the fields and forming a list object like as below
private static MechanicalData TransformMechanicalData(MechanicalData sourceMechanicalData, Dictionary<string, MasterSection> masterSectionMappedLibrary)
{
return new MechanicalData()
{
InternalLoadsLighting = sourceMechanicalData.InternalLoadsLighting
.Where(a => a != null)
.Select(libraryLighting => new LibraryLighting
{
Id = libraryLighting.Id,
IsApproved = true,
Revision = libraryLighting.Revision,
MasterSection = masterSectionMappedLibrary["Library Lighting"],
SourceOfDataId = libraryLighting.SourceOfData.Id,
LightingDensity = libraryLighting.LightingDensity
.....
}).ToList() ?? new(),
InternalLoadsEquipment = sourceMechanicalData.InternalLoadsEquipment
.Where(a => a != null)
.Select(libraryEquipment => new LibraryEquipment
{
MasterSection = masterSectionMappedLibrary["Library Equipment"],
SourceOfData = libraryEquipment.SourceOfData,
EquipmentDensity = libraryEquipment.EquipmentDensity,
Id = libraryEquipment.Id,
IsApproved = true,
Revision = libraryEquipment.Revision,
......
....
}).ToList() ?? new(),
}
}
Is there any way i can apply dynamic type to simplify the above values assign or any suggestion with linq dynamic select query using reflection method that would be very grateful to me, TIA.
Aucun commentaire:
Enregistrer un commentaire