【发布时间】:2018-12-10 20:18:04
【问题描述】:
我传递了一个参数month 并附加到一个列表中。
如何将列表添加到SqlQuery 参数?
错误:不存在从对象类型 System.Collections.Generic.List`1[] 到已知托管提供程序本机类型的映射。
public ActionResult filterhre(int? month, int? year)
{
List<int> lst = new List<int>();
for (int i = 1; i <= @month; i++)
{
lst.Add(i);
}
ViewBag.location_fraud_year = db.Database.SqlQuery<YearCheck>(@"SELECT fraud_location, count(claim_amount) as counting_claim, sum(claim_amount) as counting_sum FROM testtable
where month(datelocation) in ({0}) and year(datelocation)={1} and fraud_location is not null ",lst, year).ToList();
}
型号:
public class YearCheck
{
public string fraud_location { get; set; }
public int? counting_claim { get; set; }
public decimal? counting_sum { get; set; }
}
【问题讨论】:
-
location_fraud_year的类型是什么?您是否有从List<int>转换为它的类型的隐式转换? -
"where month(datelocation) < {0}"就够了