开发者

Can you call UDF with Entity Framework 4 without using wizards?

A confession to make: without any permission, I rewrote the NerdDinner tutorial wi开发者_C百科th .NET Framework 4 and Entity Framework 4, instead of LINQ to SQL, as I was fascinated with the concept of Code-first approach and Razor cshhtml template!

Nevertheless, when I reached the point where I have to use UDF to find nearest dinner, Entity Framework 4 proved to be very challenging.

Therefore, I would be grateful if anyone could point me to documentation about Entity Framework 4, which explains how to call UDF functions, as MSDN failed to get me around this – I spent 2 hours and forty five minutes on http://msdn.microsoft.com/en-us/library/dd456857.aspx and it did not help. May be brain is become useless!!!

The answer I am looking for is: Can you call UDF with Entity Framework 4 without using wizards?

If the answer is yes, let me know how that can be done.

Many thanks in advance.


No Entity framework can't import UDFs. You can only import Stored procedures. UDFs can be called directly using standard SQL and DbContext.Database.SqlQuery. If you create data type which will have same properties as SQL result set, SqlQuery will be able to use that type.


The answer to your question is: yes, you can.

Take a look at this http://msdn.microsoft.com/en-us/library/dd456847(v=vs.100).aspx


You can wrap UDFs with Stored Procs and import those.

CREATE PROCEDURE [dbo].[usp_sel_MyCustomUDF]
    @Parameter int = null                   
BEGIN

    SET NOCOUNT ON;

    SELECT * FROM [dbo].[udf_MyCustomUDF] Parameter) 

END
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜