首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >方法'Boolean In[Int32](Int32,Int32[])不支持转换为SQL

方法'Boolean In[Int32](Int32,Int32[])不支持转换为SQL
EN

Stack Overflow用户
提问于 2012-05-22 22:53:25
回答 1查看 784关注 0票数 0

我有以下方法:

代码语言:javascript
复制
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;
        }

它使用扩展方法:

代码语言:javascript
复制
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。

我相信,不用使用扩展方法,这是有意义的。谁能给我指明正确的方向吗?

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-22 22:54:43

使用:

代码语言:javascript
复制
alertTypes.Contains(a.AlertTypeID)

而不是。

代码语言:javascript
复制
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();
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10711244

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档