In my database I have define some function, let\'s say it\'s called fnTest
.
Is it possible to call that function from my LINQ/EF query? Something like this:
First off, fnTest
will have to be created as a user-defined function in the database first:
CREATE FUNCTION [fnTest] (@fi int, @f2 int, @param3 int, @param4 int)
RETURNS int
AS ...
Then in your .edmx file, declare the function like this:
Now you can bind this function to a method in your model like this:
[EdmFunction("MyNamespace", "fnTest")]
public static int fnTest(int f1, int f2, int param3, int param4)
{
throw new NotSupportedException("Direct calls are not supported.");
}
You can now use this method in standard LINQ queries.
Further Reading