I have a snippet of LINQ code that I need to use in a lot of queries
let catchmentId = Convert.ToInt32(
phy.PhysicalProperty_binData.Substring(offset + 3
The links on this page will show you how you can use custom attributes to tie your extension method to a user-defined function in your database.
Of course, that will mean that you need to create a user-defined function in SQL to do the same logic that your extension method wants to do.
Another option is to have your extension method produce an Expression
, and use LINQKit to parse through the query tree, finding the call to .Compile()
off of that expression, and inlining that expression in the query.