c# - LINQ On DbContext.Set() -
c# - LINQ On DbContext.Set() -
so, trying dbset
returned entity name (string). how far have gotten:
var customers = db.set(type.gettype("app.model.customer, app.model, version=1.0.0.0, culture=neutral, publickeytoken=null"));
but cannot perform other linq any()
or single()
. why , how can alter so?
the non-generic overload of dbcontext.set
returns as non-generic dbset
. 1 of interfaces class implements iqueryable
, again, non generic. that's reason why can't serve input of these linq extension method defined on generic type iqueryable<t>
.
so in fact, if still want utilize linq, postpone moment when have convert generic iqueryable
. could do...
var customers = db.set(type.gettype(...)).cast<customer>().where(c => ...)
...but of course of study lose whole point of defining type dynamically, @ runtime.
once start dynamically, have go on dynamically. 1 way adding system.linq.dynamic
project. can write queries like...
var customers = db.set(type.gettype(...)).where("customerid = @0", 1);
...which homecoming customer
(wrapped in iqueryable<customer>
) having customerid == 1
.
you can utilize find
method:
var client = db.set(type.gettype(...)).find(1);
this homecoming single customer
instance.
c# linq entity-framework reflection
Comments
Post a Comment