.net 将不在的SQL查询转换为Linq

.net 将不在的SQL查询转换为Linq,.net,model-view-controller,.net,Model View Controller,如何将此SQL查询转换为Linq? 有一个not in语句我无法转换 SQL 林克 public静态IEnumerable GetProductName() { 使用(WALLET\u CORE\u Attenties=新的WALLET\u CORE\u Attenties()) { 返回新的SelectList(_ent.SW_TBL_KEYWORD.Where(x=>x.KEYWORD_Scope==“A”&&x.KEYWORD!=“ATRF” &&x.关键字!=“演员” &&x.关键字!=

如何将此SQL查询转换为Linq? 有一个not in语句我无法转换

SQL

林克

public静态IEnumerable GetProductName()
{
使用(WALLET\u CORE\u Attenties=新的WALLET\u CORE\u Attenties())
{
返回新的SelectList(_ent.SW_TBL_KEYWORD.Where(x=>x.KEYWORD_Scope==“A”&&x.KEYWORD!=“ATRF”
&&x.关键字!=“演员”
&&x.关键字!=“评估”
&&x.关键字!=“FTBS”
&&x.关键字!=“KYCB”
&&x.关键字!=“RCAN”
&&x.关键字!=“RDPT”
&&x.关键字!=“REGA”
&&x.关键字!=“演员”
&&x.关键字!=“REGC”)
.ToList(),“关键字”,“关键字描述”);
}
}

您可以使用
Contains
方法的否定:

private static readonly HashSet<string> excludeKeywords = 
    new HashSet<string>(StringComparer.CurrentCultureIgnoreCase)
    { "ATRF", "CAST", "EVAL", "FTBS", "KYCB", "RCAN", "RDPT", "REGA", "CAST", "REGC" };

public static IEnumerable<SelectListItem> GetProductName()
{
    using (WALLET_CORE_UATEntities _ent = new WALLET_CORE_UATEntities())
    {
        var result = _ent.SW_TBL_KEYWORD.Where(x =>
            x.Keyword_Scope == "A" &&
            !excludeKeywords.Contains(x.Keyword));  /* NOT IN check */

        return new SelectList(result.ToList(), "Keyword", "Keyword_Description");
    }
}
private static readonly HashSet excludeKeywords=
新哈希集(StringComparer.CurrentCultureIgnoreCase)
{“ATRF”、“CAST”、“EVAL”、“FTBS”、“KYCB”、“RCAN”、“RDPT”、“REGA”、“CAST”、“REGC”};
公共静态IEnumerable GetProductName()
{
使用(WALLET\u CORE\u Attenties=新的WALLET\u CORE\u Attenties())
{
var result=\u ent.SW\u TBL\u关键字。其中(x=>
x、 关键字_范围==“A”&&
!excludeKeywords.Contains(x.keywords));/*未处于检查状态*/
返回新的SelectList(result.ToList(),“关键字”,“关键字描述”);
}
}

可能的重复投票我已撤回重复投票;这个问题与另一个问题相反。在这里包含什么;我添加了该注释,以表明这是执行
NOT IN
检查的等价行。我会修正这个评论。
    public static IEnumerable<SelectListItem> GetProductName()
    {
        using (WALLET_CORE_UATEntities _ent = new WALLET_CORE_UATEntities())
        {
            return new SelectList(_ent.SW_TBL_KEYWORD.Where(x => x.Keyword_Scope == "A" && x.Keyword!= "ATRF" 
            && x.Keyword!= "CAST" 
            && x.Keyword != "EVAL"
            && x.Keyword != "FTBS"
            && x.Keyword != "KYCB"
            && x.Keyword != "RCAN"
            && x.Keyword != "RDPT"
            && x.Keyword != "REGA"
            && x.Keyword != "CAST"
            && x.Keyword != "REGC")
            .ToList(),"Keyword","Keyword_Description");
        }

    }
private static readonly HashSet<string> excludeKeywords = 
    new HashSet<string>(StringComparer.CurrentCultureIgnoreCase)
    { "ATRF", "CAST", "EVAL", "FTBS", "KYCB", "RCAN", "RDPT", "REGA", "CAST", "REGC" };

public static IEnumerable<SelectListItem> GetProductName()
{
    using (WALLET_CORE_UATEntities _ent = new WALLET_CORE_UATEntities())
    {
        var result = _ent.SW_TBL_KEYWORD.Where(x =>
            x.Keyword_Scope == "A" &&
            !excludeKeywords.Contains(x.Keyword));  /* NOT IN check */

        return new SelectList(result.ToList(), "Keyword", "Keyword_Description");
    }
}