sql - Flatten list with EF SelectMany -
i want go ahead , or @ least of columns projects table has 1 many relationship timetrackings table.
when create query, child (timetracking entity) fields come out , id of parent (project table).
how can achieve effective join using selectmany flatten list getting columns or @ least specifying specific columns each of 2 entities.
below, ef query i'm using:
customers.selectmany(p => p.projects).where (p => p.quote != null).selectmany (t => t.timetrackings).where (t => t.notes != null)
below generated sql query via linqpad. notice how projectid , not rest of associated columns entity come out.
select [extent2].[timetrackingid] [timetrackingid], [extent2].[projectid] [projectid], [extent2].[startdate] [startdate], [extent2].[enddate] [enddate], [extent2].[notes] [notes], [extent2].[createddate] [createddate], [extent2].[updateddate] [updateddate] [dbo].[projects] [extent1] inner join [dbo].[timetrackings] [extent2] on [extent1].[projectid] = [extent2].[projectid] ([extent1].[quote] not null) , ([extent2].[notes] not null)
below, output of query:
you can form linq following
from c in customers p in c.projects t in p.timetrackings p.quotes != null t.notes != null select new { project = p, timetrack = t }
also, can change select statement project individual properties
select new { projectid = p.id, timetrackid = t.id, = p.anything }
Comments
Post a Comment