且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Sql存储过程和实体框架6

更新时间:2023-02-13 17:02:44

经过很多挫折,我找到了一种方式,周围。这个对我来说很好,而且它不需要额外的C#代码,没有模型,没有这样的东西,例如 public class FunctionsContext:BaseContext< FunctionsContext> {} 那就是...

After lots of frustrations, i found a way, but it's another work around. This one works pretty well for me though, and it does not require extra C# code, no model, and no such things as public class FunctionsContext : BaseContext<FunctionsContext>{} whatever that is...

在SQL Server中,我创建了一个空表,就像我的存储过程的返回一样。假设我的存储过程是返回:

In SQL Server, i created an empty table that looks just like the return of my stored procedure. Suppose my stored procedure was to return :

SELECT nvarchar(2), int, datetime FROM whatever WHERE <condition>

然后我的Empty_Table使用相同的var类型创建。在将我的Empty_Table与实体框架映射向导映射之后。我可以使用它作为一种类型:

Then my Empty_Table is created with the same var types. After mapping my Empty_Table with Entity framework mapping wizard. I could use it as a type to to this :

databaseEntities db = new databaseEntities();

var query = db.Database.SqlQuery<Empty_Table>("EXEC [dbo].[My_Stored_Proc] @p1", new SqlParameter("p1", parameterValue));

foreach (var line in query)
{
    int i = line.ID
}

它工作得很好。这将是使用实体使用存储过程的主要(唯一)技术。

And it worked perfectly. This is going to be my main (only) technique for using stored procedure with Entity.