我的上一个问题得到了很好的答案,但实际上更复杂:
我需要向这个存储过程传递一个整数列表:
ALTER proc [dbo].[Invoice_GetHomePageInvoices] (
@AreaIdList varchar(max)
, @FinancialYearStartDate datetime = null
, @FinancialYearEndDate datetime = null
这是我到目前为止所拥有的:
public virtual IEnumerable<HomePageInvoice> GetHomePageInvoices(IList<Area> areas, FinancialYearLookup financialYear)
{
var areaIds = areas.Select(x => x.Id).ToList();
//return _db.Database.SqlQuery<HomePageInvoice>(string.Format("EXEC Invoice_GetHomePageInvoices @AreaIdList = '{0}', @FinancialYearStartDate = '{1}', @FinancialYearEndDate = '{2}'", areas.ToString(), financialYear.StartDate.ToString(), financialYear.EndDate.ToString()));
var startDate = new SqlParameter("FinancialYearStartDate", financialYear.StartDate);
var endDate = new SqlParameter("FinancialYearEndDate", financialYear.EndDate);
return _db.Database.SqlQuery<HomePageInvoice>("Invoice_GetHomePageInvoices", startDate, endDate);
}
因此对日期时间参数进行了排序。List<int>
但是,鉴于我当前有一个和 sql 期望,你将如何将 ids 发送到存储过程@AreaIdList varchar(max)