I want to get records from the database using EF and assign the values to a DTO class.Consider the following tables for a Linq query.
TableA,TableB, TableC
F
I would change your DTO from List to IEnumerable and than do everything in a LINQ query.
var query =
from ent in TableA
select new TableA_DTO
{
TableAProperty = a.Property,
TableB_records =
from b in TableB
where ent.Key == b.Key
select new TableB_DTO
{
TableBProperty = b.Property,
TableC_records =
from c in TableC
where b.Key == c.Key
select new TableC_DTO
{
TableCProperty = c.Property
}
}
};