I want to use SqlFunctions.StringConvert() in many places in different projects in my solution.
I dont want each project to hold reference to system.data.entity so I decided to put a wrapper in my Common project (all other projects has reference to Common).
How can I write such wrapper? If I am doing:
public static class SqlUtils
{
public static Func<decimal?, string> StringConvert()
{
return x => SqlFunctions.StringConvert(x);
}
public static Func<double?, string> StringConvert()
{
return x => SqlFunctions.StringConvert(x);
}
}
Then I cannot use it like:
query.Where(x => SqlUtils.StringConvert((decimal)x.SerialNumber).Contains(serialNumber));
because entity framework don’t know the method SqlUtils.StringConvert.
Any ideas how to do it?
If you want EF to be able to translate it all down to SQL, you have to more work, see: http://blogs.microsoft.co.il/blogs/gilf/archive/2010/01/01/defining-custom-functions-in-entity-framework.aspx