Hello,
I have multiple tables with an "id" component. I'd like to use LINQ to get an item from one of these tables with the correct LINQ-To-SQL type, but only using one CompiledQuery.
Here's an example that works currently. Say the object type defined in the DBML is "myitem" and its table is "myitems".
var getOneItem = CompiledQuery.Compile(
(MyDataContext db, long id) => ((from i in db.myitems
where i.id == id
select i).SingleOrDefault()));
I'd like to make this, where the type can be "myitem", "myitems2", or whatever table and object type I might be interested in.
var getOneItemAnyTable = CompiledQuery.Compile(
(Table tab, Type T long id) => ((from anItem in tab<T>
where anItem.id == id
select anItem).SingleOrDefault()));
I made up this syntax because I'm not sure what the syntax should look like here. Any ideas if it's possible? Would I have to munge the DBML to make some kind of superclass for the types involved?
Thank you.