c# - Entity framework `AsNoTracking` is not working with anonymous projection -
in below snipped try fetch data using anonymous projection , not track entities fetched.
note : have gone through existing stack question,yet unable find working solution me
using (var db = new entities()) { db.configuration.lazyloadingenabled = false; db.configuration.proxycreationenabled = false; var myprojection = db.table1 .asnotracking() .include(gh=>gh.table2) //update .include(gh=>gh.table3) //update .select(x => new { table1= x, table2= x.table2.where(g => condition), table3= x.table3.where(g=>some condition) }) .tolist(); var result = myprojection.select(g =>g.table1).firstordefault(); } when use
asnotracking()data inner tables (table2,3) lost during conversion @ linevar result = myprojection.select(g =>g.table1).firstordefault();
edit
if remove
asnotracking()works fine.
1) how use projection , asnotracking in entity framework correctly ?
2) other option remove tracking of query?
is there possible workarounds?
use tolist() navigation properties. note still projekt in db. (ef6)
// .. table2 = x.table2.where(g => condition).tolist(), update:
with ef4 need map table2 manually:
table2 = x.table2.where(g => condition).select(x => new {foo = x.bar}),
Comments
Post a Comment