views:

528

answers:

1

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?

+1  A: 

Use .OfType():

var qry = from i in _DB.BaseTable.OfType<InheritedTable>()
          select i.InheritedTableField;
Craig Stuntz
Graig, A Tip of the hat to you sir. It appears you've solved my problem. Much'o Thanks'o.BTW - Know of any good references for Linq to entities queries when using inheritance?
CraftyFella