多个结果集与codeFirst

多个结果集与codeFirst

本文介绍了实体框架存储过程 - 多个结果集与codeFirst的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是低于code获得常规结果从存储过程:

I am using the below code to get a regular result from a stored procedure:

var paramUserId = new SqlParameter
{
    ParameterName = "userId",
    Value = userId
};

string query = string.Format("{0} {1}",
              "SpSetFoo",
              "@userId");

var results = context.Database.SqlQuery<FooModel>(query,
                                             paramUserId);

result = results.ToList();

同时,我需要从另一个存储过程,我发现它根据该文件有可能检索多个结果集:http://msdn.microsoft.com/en-us/data/jj691402.aspx

不过从微软的例子是使用ADO.NET。它不可能使用EF代替来达到同样的结果,而不ADO.NET

However the example from Microsoft is using ADO.NET. It's not possible to achieve the same result without ADO.NET using EF instead?

感谢

推荐答案

这是一个老话题,但以防万一有人在这里添加注释需要它。我需要消耗从不同的数据库,然后处理返回的数据存储到我们的应用程序数据库之后,返回了两个表的存储过程。所指的标准文件和遵循的步骤,但不喜欢它。首先有问题和code暴露出一些软肋,这不是但从可维护性来说是个好主意。

This is an old topic but adding comments here just in case someone needs it. I needed to consume a stored proc that returned two tables from a different database and then after processing the returned data storing into our application database. Referred to the standard documentation and followed the steps but did not like it. First there were problems and the code exposed some underbelly that was not a good idea from maintainability point of view.

这其中的NuGet包专为处理SP的设计进入画面。看看。辉煌的包非常具体的重点和做这项工作完美。此返回每个结果集存储过程,那么可以使用任何所需的方式的对象的集合。他们是不同版本的EF,包括6还要检查code项目的的。下载源$ C ​​$ C甚至有一个PDF,介绍如何在详细步骤中使用它。

That where a Nuget package designed specifically for handling SPs come into picture. Take a look at CodeFirstStoredProcs. Brilliant package with very specific focus and does the job perfectly. This returns a collection of objects for each result set of stored proc that can then be used any way desired. Their is a good and consistent support for different versions of EF including version 6. Also check the explanation on code project Code First Stored Procedures. Downloaded source code even has a PDF that explains how to use it in detailed steps.

非常感谢作者aureolin。

Big thanks to the author aureolin.

这篇关于实体框架存储过程 - 多个结果集与codeFirst的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 01:54