Entity Framework casting issue -


i have entity framework issue. have code, mytype2 derives mytype1:

var ef = appdbcontext.current; var result = ef.set<mytype1>().where(   x => x.type == "mytype2" &&   ef.set<mytype2>().any(y => y.code == ((mytype2)x).code) ); 

when run it, throws 'notsupportedexception': unable cast type 'mytype1' type 'mytype2'. linq entities supports casting edm primitive or enumeration types.

how can cast mytype1 mytype2?

not every mytype1 type mytype2, however, every mytype2 type of mytype1. why cannot (and should not) convert mytype1 instance mytype2.

you can use .oftype<> in case, example, , not sure work 100% you, may give idea:

var mytype2instances = dbcontext.mytype1.oftype<mytype2>().list(); 

Popular posts from this blog