Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linq to entities inheritance query problem

I'm trying to perform a linq to entities query on a table that's inherited using Table per Type.

The problem I'm having is that I can't get at the properties on the Inhertied table only the properties on the Base Table.

var qry = from i in _DB.BaseTable
where i is catalogueModel.InheritedTable
// Field Doesn't Exist
// && i.InheritedTableField == "Value"
select i;

When I try to cast the Inherited Table to it's type...

var qry = from i in _DB.BaseTable
where i is catalogueModel.InheritedTable
&& (i as catalogueModel.InheritedTable).InheritedTableField  == "Value"
select i;

...the code compiles but i get a cool error which reads

Only text pointers are allowed in work tables, never text, ntext, or image columns. The query processor produced a query plan that required a text, ntext, or image column in a work table.

I suppose my question is How are you supposed to access the properties of the Inherited tables in linq to entities when using Table per Type?

like image 973
CraftyFella Avatar asked Mar 01 '23 00:03

CraftyFella


1 Answers

Use .OfType():

var qry = from i in _DB.BaseTable.OfType<InheritedTable>()
          select i.InheritedTableField;
like image 112
Craig Stuntz Avatar answered Mar 12 '23 02:03

Craig Stuntz