c# - Join between in memory collection and EntityFramework -


is there mechanism doing join between in-memory collection , entity framework while preserving order.

what trying

var itemstoadd =    myinmemorylist.join(efrepo.all(), listitem => listitem.record_number,   efrepoitem => efrepoitem.record_number, (left, right) => right); 

which gives me rather curiously titled "this method supports linq entities infrastructure , not intended used directly code." error.

now of course can iteratively like

        foreach (var item in myinmemorylist)         {             var ho = efrepo.where(h => h.record_number == item.record_number).firstordefault();             tmp.add(ho);         } 

but n+1 query. nasty myinmemorylist might quite large!

resharper can refactor me

        tmp = (from typeofiteminthelist item in myinmemorylist             select efrepo.where(h => h.record_number == item.record_number)            .firstordefault()); 

which suspect still doing n+1 queries. ideas better approach getting ef entities match (on key field) in-memory collection. resulting set must in same order in-memory collection was.

no cannot join in-memory collection database result set without loading whole result set memory , performing join linq-to-objects. try using contains instead of join:

var mynumbers = myinmemorylist.select(i => i.record_number); var itemstoadd = efrepo.where(e => mynumbers.contains(e.record_number)); 

this generate query in operator


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -