Recently I have been working heavily in SQL server writing SPROCS but using a few User defined functions just to make things easier. Well this morning I was back knee deep in .NET code and thought wouldn’t it be nice if I could use the Entity Framework to call out to my helper UDFs.
Well the answer is that its possible, infact its actually very simple, the only problem I found was that there were not many easy to understand articles on how to accompish this on the net.
So here is a quick Post on how to call User Defined Functions and return a Scalar Value from the Entity Framework.
Firstly we need to add the function to the Model Store. Do to this open the Model Browser Window, Right-Click the Stored Procedures Folder and Select ‘Update Model from Database’
Once the function has been added, you can only call the function via SQL directly so in your code write some thing similar to this:
And thats all there is to it. Told you it was easy!!