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

# re: HUGE EF4 Inheritance Bug

Wednesday, April 28, 2010 7:22 PM by Keith

Would of been better if the title was Huge EFing Bug :-)

But yeah, this sucks.  

This should would work out better if it was a table per class?  have you tried? or you locked in to single table inheritance?

# re: HUGE EF4 Inheritance Bug

Wednesday, April 28, 2010 7:22 PM by anas

one off topic question:

From where you get that template for your blog ?

I have blog here , but i don't see your template in the templates settings in my control panel.

Thanks :)

# re: HUGE EF4 Inheritance Bug

Thursday, April 29, 2010 4:15 AM by Alberto Diaz

How is it possible? I have the same bug that you.

# re: HUGE EF4 Inheritance Bug

Thursday, April 29, 2010 4:21 AM by Alberto Diaz

Can you try to delete the Include clause? I think it's worked without it

# re: HUGE EF4 Inheritance Bug

Thursday, April 29, 2010 5:12 AM by djsolid

@Alberto Diaz

This is the bug exactly. Include doesn't work. You must always do a separate query to load navigation properties.

@anas

It is a free template and I applied to this blog using CSS Overrides

@Keith

I haven't tried TPC Inheritance. I will try later and post the results.

# re: HUGE EF4 Inheritance Bug

Friday, July 30, 2010 2:46 PM by Ashraf

Why not BurgerDetail inherited from Burger problem. solved.

# re: HUGE EF4 Inheritance Bug

Tuesday, August 17, 2010 7:35 AM by DS

So when will this be fixed??

# re: HUGE EF4 Inheritance Bug

Tuesday, September 14, 2010 5:33 AM by Rih

I have exactly the same problem!!! This is frustrating.

# re: HUGE EF4 Inheritance Bug

Thursday, October 21, 2010 8:46 AM by Job Vermeulen

@Ashraf

Then a join will ALWAYS happen even if you only need the Burger.

Leave a Comment

(required) 
(required) 
(optional)
(required)