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'
...
}
精彩评论