HUGE EF4 Inheritance Bug - Web Dev And Stuff
Wednesday, April 28, 2010 10:49 PM djsolid

HUGE EF4 Inheritance Bug

Well maybe not for everyone but for me is definitely really important.

That is why I get straight into the point.

We have the following model:

image

Which maps to the following database:

image

We are using EF4.0 and we want to load all Burgers including BurgerDetails.

So we write the following query:

image

But it fails. The error is :

The ResultType of the specified expression is not compatible with the required type. The expression ResultType is 'Transient.reference[SampleEFDBModel.Food]' but the required type is 'Transient.reference[SampleEFDBModel.Burger]'.Parameter name: arguments[0]

 

So in the new version of EF there is no way to eager load data through Navigation Properties with 1-1 relationships defined in subclasses.

Here is the relevant Microsoft Connect Issue. It is described through an other example but the result is the same.  Please if you think this is important vote up on Microsoft Connect.

 

EF 4.0 has many improvements. I am using it since v1 in large-scale projects and this version is faster,produces cleaner sql, more reliable and can be used for complicated business scenarios. That is why I believe this issue should be solved as soon as possible. I understand that release cycles are slow but I am hoping atleast for a hotfix.

I also have uploaded the example project so you can test it. Download it from here.

If anyone has found any workarounds please post it in the comments section.

Thanks!

Filed under: , , ,

Comments

No Comments