Print Page | Close Window

EntityServerException on a query with a subquery on an inherited entity

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3463
Printed Date: 13-May-2026 at 5:42am


Topic: EntityServerException on a query with a subquery on an inherited entity
Posted By: Walid
Subject: EntityServerException on a query with a subquery on an inherited entity
Date Posted: 29-May-2012 at 9:40am
Hi,


I am getting an error during the execution of a query on a model where exist TPH inheritance.

EntityServerException: Une expression de type 'System.Data.Objects.ObjectQuery`1[ConsoleApplication4.Company]' ne peut pas être utilisée pour un paramètre de type 'System.Linq.IQueryable`1[ConsoleApplication4.GamingCompany]' d'une méthode 'System.Linq.IQueryable`1[ConsoleApplication4.GamingCompany] Where[GamingCompany](System.Linq.IQueryable`1[ConsoleApplication4.GamingCompany], 
System.Linq.Expressions.Expression`1[System.Func`2[ConsoleApplication4.GamingCompany,System.Boolean]])'


My model has an entity GamingCompany which inherit from the entity Company. The model looks like this :
Here is the query         
                    from c in Customers
                    from o in c.Orders
                    let companyGroupId = (from e in GamingCompanies where (e.ID == 0) select e.CompanyGroupId).FirstOrDefault()
                    where (o.GamingCompany.CompanyGroupId == companyGroupId)
                    select c;




Now I made a model where I broke the inheritance and the modified query works.

 
            var q = from c in Customers
                    from o in c.Orders
                    let companyGroupId = (from e in Companies where (e.ID == 0 && e.Discriminant == 1) select e.FirstOrDefault()
                    where (o.Company.CompanyGroupId == companyGroupId)
                    select c;


What am I doing wrong ? Is it not allowed to do subquery on a inherited entity ?

Regards,


EDIT  : on the first model, if the CompanyGroup relation is on Company and not GamingCompany it's working. Unfortunatly I need it on GamingCompany ...





Replies:
Posted By: sbelini
Date Posted: 31-May-2012 at 10:53am
Hi Walid,
 
I was able to reproduce the issue and will file a bug in this regard.
In the meantime, a workaround would be to define companyGroupId separately:
 
var companyGroupId = (from e in GamingCompanies where (e.ID == 0) select e.CompanyGroupId).FirstOrDefault()
var q = from c in Customers
            from o in c.Orders                   
            where (o.GamingCompany.CompanyGroupId == companyGroupId)                   
            select c;
 
Regards,
   Silvio.


Posted By: Walid
Date Posted: 31-May-2012 at 11:14am
Hi silvio,
 
That's is what I did.
I hope you will be able to fix it for the next release because I have more query like this one and it's a SL application. I would like to avoid to execute 2 async query each time.
 
Regards,
 
 



Print Page | Close Window