Create a custom function on your SQL server that will be equivalent to your C # code. Let's say it was called "dbo.SatsFilter".
Create a datacontext override method, let's say it looks like this:
public bool SatisfiesFilter(string name, string filter) {
Decorate the C # method with the [Function] and [Parameter] attributes so that it looks something like this:
[Function(Name="dbo.SatsFilter",IsComposable=true)] public bool SatisfiesFilter([Parameter name="@name",DbType="nvarchar(50)"]string name, [Parameter name="@filter",DbType="nvarchar(50)"]string filter)
IsComposable=true means its function, not a stored procedure, and therefore can be used as part of a larger request.
Now you can use this DataContext method and, if necessary, it will be converted to SQL, or C # will be used in queries executed in memory.
Note also that if you just want to use SQL all the time (sometimes useful), you could call SQL when the method is called in C # code:
[Function(Name="dbo.SatsFilter",IsComposable=true)] public bool SatisfiesFilter([Parameter name="@name",DbType="nvarchar(50)"]string name, [Parameter name="@filter",DbType="nvarchar(50)"]string filter) { return (bool)ExecuteMethodCall(this, (MethodInfo)MethodInfo.GetCurrentMethod(), name, filter).ReturnValue; }
This is not very useful when the C # equivalent is convenient, since it means getting into the database and some translation, but useful if the user function depends on the state of the database or it is difficult to translate to C #