开发者

Linq to SQL - is there a way to map an extension method to a SQL Function/Stored Procedure?

I have an extension method for the DateTime type that I would like to use in my Linq to Sql. Unfortunately, doing a ToList() and then using the extension method is not an option. Is there a way to map an extension method to an actual S开发者_如何学编程QL Function?


Not as an extension method, no; mapped functions must be called as instance functions from the data-context, i.e.

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

and used in some form such as:

using(var dc = new MyDataContext(...))
{
     var qry = from ...
               where dc.FunctionName(row.CreationDate) == 'Whatever'
               ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜