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 SQL 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'
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With