在.net core中使用多个结果集 [英] Working with multiple resultset in .net core
问题描述
使用存储过程检索结果时,如何在.net核心的视图模型中检索和存储多个结果集
While retrieving the results using stored procedure how can I retrieve and store multiple result set in view model in .net core
例如从存储过程中,我将返回以下两个查询的记录
For e.g. from stored procedure I am returning records for below two queries
Select * LMS_Survey
Select * from LMS_SurveyQuestion
Select * from LMS_SurveyQuestionOptionChoice
及以下是两个表的视图模型
and below is view model for two tables
public class LMS_SurveyTraineeViewModel
{
public LMS_SurveyDetailsViewModel SurveyDetailsViewModel { get; set; }
public LMS_SurveyQuestionsViewModel SurveyQuestionsViewModel { get; set; }
public LMS_SurveyQuestionOptionChoiceViewModel SurveyQuestionOptionChoiceViewModel { get; set; }
}
这就是我执行存储过程的方式
This is how I am executing the stored procedure
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;
}
}
如何在视图模型中使用存储过程存储多个结果集?
How can stored the multiple result set using stored procedure in view model ?
推荐答案
当前,EF Core不支持此功能.有一个未解决的问题可以解决这个问题.
Currently, EF Core doesn't not support this. There is an open issue to address this.
https://github.com/aspnet/EntityFramework/issues/8127
更新2018年9月12日:即使对于EF Core 3.0版,这仍然不是EF Core的优先事项;因此,在有多个结果的情况下,最好使用Dapper或纯ADO.NET
Update 12th Sep 2018: This is still not a priority for EF Core even for release 3.0; so best use Dapper or plain ADO.NET when you have multiple results scenario
更新2020年6月25日:EF Core仍在积压中,即使是5.0版;因此,在有多个结果的情况下,最好使用Dapper或纯ADO.NET
Update 25th Jun 2020: still on the backlog for EF Core even for release 5.0; so best use Dapper or plain ADO.NET when you have multiple results scenario
这篇关于在.net core中使用多个结果集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!