在.net核心中使用多个结果集

Xam*_*Dev 8 c# entity-framework-core asp.net-core-mvc asp.net-core

在使用存储过程检索结果时,如何在.net核心的视图模型中检索和存储多个结果集

例如,从存储过程我返回两个以下查询的记录

Select * LMS_Survey
Select * from LMS_SurveyQuestion
Select * from LMS_SurveyQuestionOptionChoice
Run Code Online (Sandbox Code Playgroud)

以下是两个表的视图模型

public class LMS_SurveyTraineeViewModel
{
    public LMS_SurveyDetailsViewModel SurveyDetailsViewModel { get; set; }
    public LMS_SurveyQuestionsViewModel SurveyQuestionsViewModel { get; set; }
    public LMS_SurveyQuestionOptionChoiceViewModel SurveyQuestionOptionChoiceViewModel { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

这就是我执行存储过程的方式

public List<LMS_SurveyTraineeViewModel> GetTraineeSurvey(int surveyID)
        {
            try
            {
                List<LMS_SurveyTraineeViewModel> modelList = new List<LMS_SurveyTraineeViewModel>();

                modelList = dbcontext.Set<LMS_SurveyTraineeViewModel>().FromSql("LMSSP_GetTraineeSurvey @surveyID = {0},@LanguageID = {1}", surveyID, AppTenant.SelectedLanguageID).ToList();

                return modelList;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Run Code Online (Sandbox Code Playgroud)

如何在视图模型中使用存储过程存储多个结果集?

Ric*_*y G 8

目前,EF Core并不支持此功能.有一个未解决的问题需要解决这个问题.

https://github.com/aspnet/EntityFramework/issues/8127

更新2018年9月12日:即使对于3.0版本,这仍然不是EF Core的优先考虑事项; 因此,当您有多个结果场景时,最好使用Dapper或普通ADO.NET

  • 它有望在今年年中排在积压工作的首位 https://github.com/aspnet/EntityFramework/milestone/2 (2认同)
  • @mehaboob 看起来仍然处于积压状态,并且不针对任何版本 (2认同)