我有以下方法:
public List<Alert> GetMonthlyAlertsByAccountID(Int32 AccountID, params int[] alertTypes)
{
List<Alert> result = new List<Alert>();
using (NeuroLabLinqDataContext dc = conn.GetContext())
{
IEnumerable<Alert> alerts = (from a in dc.Alerts
where a.AccountID == AccountID &&
a.AlertTypeID.In(alertTypes)
orderby ((DateTime)a.CreateDate).Month ascending
select a).ToList();
}
return result;
}它使用扩展方法:
public static bool In<T>(this T t, params T[] values)
{
foreach (T value in values)
{
if (t.Equals(value))
{
return true;
}
}
return false;
}它的目的是只返回具有某些AlertTypeID的项。
结果是:
方法‘Int32中的布尔’不支持转换到SQL。
我相信,不用使用扩展方法,这是有意义的。谁能给我指明正确的方向吗?
谢谢。
发布于 2012-05-22 22:54:43
使用:
alertTypes.Contains(a.AlertTypeID)而不是。
IEnumerable<Alert> alerts = (from a in dc.Alerts
where a.AccountID == AccountID &&
alertTypes.Contains(a.AlertTypeID)
orderby ((DateTime)a.CreateDate).Month ascending
select a).ToList();https://stackoverflow.com/questions/10711244
复制相似问题