c# - LINQ Query to inner join DbContext Entities to IQueryable -


i have 2 tables, 'events' , 'services', have one-to-many relationship (each event has @ least 1 service).

i'm writing c# console application extract subset of events , extract corresponding services.

i have method extracts events iqueryable<event> object , it's working expected. when join iqueryable<event> object iqueryable<service> (as shown below) resulting object contains references different contexts , want contain iqueryable<service> results.

is there better way this?

here's 'extractservices' method:

public iqueryable<service> extractservices(iqueryable<event> events) {     using (var precertentities = new precertentities())     {         iqueryable<service> services = s in precertentities.services                                        orderby s.eventid                                        select s;          services = s in services                    join e in events on s.eventid equals e.eventid                    select s;          return services;     } 

you shouldn't need extract child relationships - ef you:

public iqueryable<service> extractservices(iqueryable<event> events) {     return events.selectmany(e => e.services).orderby(s => s.eventid); } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -