New Posts New Posts RSS Feed: EntityServerException on a query with a subquery on an inherited entity
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

EntityServerException on a query with a subquery on an inherited entity

 Post Reply Post Reply
Author
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Topic: EntityServerException on a query with a subquery on an inherited entity
    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 ...




Edited by Walid - 29-May-2012 at 9:53am
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post 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,
 
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down