Linq to SQL - 有没有办法将扩展方法映射到SQL函数/存储过程?

Jon*_*ski 5 c# linq-to-sql

我有一个DateTime类型的扩展方法,我想在我的Linq to Sql中使用.不幸的是,执行ToList()然后使用扩展方法不是一个选项.有没有办法将扩展方法映射到实际的SQL函数?

Mar*_*ell 2

不作为扩展方法,不;映射函数必须从数据上下文中作为实例函数调用,即

partial class MyDataContext
{
     [Function(Name="MySqlFunctionName", IsComposable=true)] 
     public ReturnType FunctionName(...args...) 
     { ... optional C# impl for AsEnumerable(),
           else throw NotImplementedException... }
}
Run Code Online (Sandbox Code Playgroud)

并以某种形式使用,例如:

using(var dc = new MyDataContext(...))
{
     var qry = from ...
               where dc.FunctionName(row.CreationDate) == 'Whatever'
               ...
}
Run Code Online (Sandbox Code Playgroud)