I have 3 tables in a master detail relationship and I want to materialise data into a set of custom dtos' but I cant get it to work, heres my linq statement
var overView = await (from organisation in DbContext.Organisations.Include(q => q.Sites.Select(m => m.Meters)
select new AggregateDto
{
Organisation = new OrganisationDto { Address1 = organisation.Address1, Address2 = organisation.Address2, Address3 = organisation.Address3, City = organisation.City, County = organisation.County, EmailFrom = organisation.EmailFrom, EmailIsSSL = organisation.EmailIsSSL, EmailPortNumber = organisation.EmailPortNumber, EmailServerHost = organisation.EmailServerHost, EmailServerUserName = organisation.EmailServerUserName, End_User_Org = organisation.End_User_Org, GroupId = organisation.GroupId, ID = organisation.ID, IsRetail = organisation.IsRetail, OrganisationName = organisation.OrganisationName, ParentOrganisationID = organisation.ParentOrganisationID, Postcode = organisation.Postcode, Role = organisation.Role, Status = organisation.Status, UserId = organisation.UserId, ParentOrganisationName = "", IsRetailNarrative = organisation.IsRetail == true ? "Yes" : "No", ContractType = organisation.ContractType, EmailAddress = organisation.EmailAddress },
Sites = organisation.Sites.Select(s => new Dto.Site.SiteDto { ADDRESS1 = s.ADDRESS1, ADDRESS2 = s.ADDRESS2, ADDRESS3 = s.ADDRESS3, ADDRESS4 = s.ADDRESS4, ADDRESS5 = s.ADDRESS5, End_User_Org = s.End_User_Org, ID = s.ID, POSTCODE = s.POSTCODE, LOCATION_NAME = s.LOCATION_NAME, COMMODITY = s.COMMODITY, CONTACT_EMAIL = s.CONTACT_EMAIL, CONTACT_FAX = s.CONTACT_FAX, CONTACT_NAME = s.CONTACT_NAME, CONTACT_TEL = s.CONTACT_TEL, COUNTRY = s.COUNTRY, CUSTOMER_LOCATION_ID = s.CUSTOMER_LOCATION_ID, EAC = s.EAC, SUPPLY_CAPACITY_UOM = s.SUPPLY_CAPACITY_UOM, OrgId = s.OrgId, VOLTAGE = s.VOLTAGE }).ToList(),
Meters = organisation.Sites.Meters.Select(m => new Dto.Meter.MeterDto { DURATIONTYPE = m.DURATIONTYPE, ID = m.ID, METER_TYPE = m.METER_TYPE, MPAN = m.MPAN, SiteID = m.SiteID, UNIT_OF_MEASURE = m.UNIT_OF_MEASURE, CAPACITY = m.CAPACITY, CUSTOMER_LOCATION_ID = m.CUSTOMER_LOCATION_ID, DFLT_DF_MR_DURATION_TYPE = m.DFLT_DF_MR_DURATION_TYPE, METER_SUPPLEMENTARY = m.METER_SUPPLEMENTARY }).ToList(),
ID = organisation.ID,
Contracts = null
});the statement generates a syntax error and also tells me that meters cant be found, but they are linked to sites which is linked to organisation. Can anyone tell me where im going wrong with this bit of code ? or is there a better way to go about it ?