How do you extend Linq to SQL? -
last year, scott guthrie stated “you can override raw sql linq sql uses if want absolute control on sql executed”, can’t find documentation describing extensibility method.
i modify following linq sql query:
using (northwindcontext northwind = new northwindcontext ()) { var q = row in northwind.customers let ordercount = row.orders.count () select new { row.contactname, ordercount }; }
which results in following tsql:
select [t0].[contactname], ( select count(*) [dbo].[orders] [t1] [t1].[customerid] = [t0].[customerid] ) [ordercount] [dbo].[customers] [t0]
to:
using (northwindcontext northwind = new northwindcontext ()) { var q = row in northwind.customers.with ( tablehint.nolock, tablehint.index (0)) let ordercount = row.orders.with ( tablehint.holdlock).count () select new { row.contactname, ordercount }; }
which would result in following tsql:
select [t0].[contactname], ( select count(*) [dbo].[orders] [t1] (holdlock) [t1].[customerid] = [t0].[customerid] ) [ordercount] [dbo].[customers] [t0] (nolock, index(0))
using:
public static table<tentity> with<tentity> ( table<tentity> table, params tablehint[] args) tentity : class { //todo: implement return table; } public static entityset<tentity> with<tentity> ( entityset<tentity> entityset, params tablehint[] args) tentity : class { //todo: implement return entityset; }
and
public class tablehint { //todo: implement public static tablehint nolock; public static tablehint holdlock; public static tablehint index (int id) { return null; } public static tablehint index (string name) { return null; } }
using type of linq sql extensibility, other this one. ideas?
the ability change underlying provider , modify sql did not make final cut in linq sql.
Comments
Post a Comment