Using SQL Server 2008 I'd like to run a regex on a DB value before comparing it.
I'm looking into CLR User-Defined Functions (I investigated EDM Functions but I got the impression that UDFs were more appropriate with a regex - please correct me if I'm wrong).
Ideally I'd like to make a linq call like this:
var results= db.Items.Where(i => i.CustomFormatFunction() == xyz);
So far I have this c# code:
public static partial class UserDefinedFunctions
{
[SqlFunction]
public static SqlString CustomFormatFunction(string str)
{
return Regex.Replace(Regex.Replace(HttpUtility.HtmlDecode(str), @"\s+", "-"), "[^a-zA-Z0-9/-]+", "").ToLower();
}
}
What further steps are required in order for me to be able to use it in a linq query?