c# - Strange exception in Linq-to-SQL -


i developed extension method:

public static iqueryable<t> get<t>(this datacontext datacontext) t : class {     return datacontext.gettable<t>(); } 

then tried use it:

datacontext.get<xdbcurrency>(). where(c => c.id == xcurrencyid.usd). selectmany(     c =>         datacontext.get<xdbcurrencyrate>().         where(cr =>             cr.currencyid == c.id &&             cr.starton <= datetime.utcnow &&             cr.endon > datetime.utcnow).         take(1),     (c, cr) => cr). toarray(); 

i exception member access 'xcurrencyid currencyid' of 'x.xdbcurrencyrate' not legal on type 'system.data.linq.table``1[x.xdbcurrencyrate]. when change get gettable - works! when change return type of get iqueryable<t> table<t> - crashes.

update. created xdatacontextbase class, moved get method there, inherited dbml-generated xdatacontext xdatacontextbase - unfortunately not help. magic!!

update. this.gettable<xdbcurrencyrate> works, this.xdbcurrencyrates works, this.get<xdbcurrencyrate> not works either get extension method or method in base class. way, internally this.xdbcurrencyrates implemented absolutely get. magic!!

update. looks linq-to-sql supports 2 things: either direct call of datacontext.gettable<> or call of any-named property returns system.data.linq.table<xdbcurrencyrate>. if create system.data.linq.table<xdbcurrencyrate> foo - works, when create iqueryable<xdbcurrencyrate> foo - crashes queries local collections not supported.. magic!!

any ideas?

this because initial get call not part of query tree. normal method call. second call embedded in tree , linq sql has no idea method means.

i know ef give here immediately. believe l2s capable of running such method locally , trying inline query returns. here, seems work out (or i'm wrong that).

what did create custom linq provider rewrites expression trees execute such methods locally, inline results query tree , forward linq sql. not trivial.

maybe can make asexpandable called "linq kit" (approximate spelling) work.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -