曾经被linq存储过程返回多个结果所困扰,今晚加班,问题解决,分享一下思路:
linq存储过程默认生成的代码是ISingleResult的,也就是只能返回一条结果集,我们先动手脚,将其改 成IMultipleResults 的.实体类根据不同情况更改.
linq存储过程更改前:
[Function(Name="dbo.MeterTaskStat")]
public ISingleResult<XXXX> MeterTaskStat
([Parameter(Name="MeterTaskType", DbType="Int")]
System.Nullable<int> meterTaskType,
[Parameter(Name="StartDate", DbType="DateTime")]
System.Nullable<System.DateTime> startDate,
[Parameter(Name="EndDate", DbType="DateTime")]
System.Nullable<System.DateTime> endDate)
{
IExecuteResult result =
this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())),
meterTaskType, startDate, endDate);
return ((ISingleResult<XXXXXX>)(result.ReturnValue));
}
linq存储过程更改后:
[Function(Name="dbo.MeterTaskStat")]
[ResultType(typeof(TaskStatData))]
public IMultipleResults MeterTaskStat
([Parameter(Name = "MeterTaskType", DbType = "Int")]
System.Nullable<int> meterTaskType,
[Parameter(Name = "StartDate", DbType = "DateTime")]
System.Nullable startDate,
[Parameter(Name = "EndDate", DbType = "DateTime")]
System.Nullable endDate)
{
IExecuteResult result =
this.ExecuteMethodCall
(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())),
meterTaskType, startDate, endDate);
return ((IMultipleResults)(result.ReturnValue));
}