C# Entity Framework 5.0 Generic LINQ -


i trying use generics load record dbcontext cache. using following code.

_context.set<t>().where(r => (int)r.gettype().getproperty("id").getvalue(r) == id).load(); 

this code throwing following error , cannot seem figure out how around it.

system.notsupportedexception: linq entities not recognize method 'system.object getvalue(system.object)' method, , method cannot translated store expression.

is doing possible or there way.

the problem you're attempting use reflection methods (gettype(), getproperty(), getvalue()) linq entities, , doesn't understand them. methods you're allowed use inside linq query limited query provider supports, , in case of linq entities it's things can translated sql relatively easily.

you won't able try match id way, unfortunately. using .find(id) work long primary key entity type specified t has single column , id correct type, that's going brittle approach if works in cases.

if describe scenario little bit more, people might have suggestions approach take. can explain why want generically? it's pretty unusual want execute query against dbcontext without knowing entity type you're interested in.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -