【问题标题】:Entity framework return items from list that not contained in a table实体框架从列表中返回不包含在表中的项目
【发布时间】:2015-07-17 13:52:10
【问题描述】:

我是使用实体框架的新手 我有一个表格编号列表,我想从表格中搜索表格编号列表,然后从表格中不包含的列表中返回表格编号 我尝试了这个查询,它给了我一半的工作:

这是我的清单:

var strPurchaseFormNoList= new List<string> { "1", "2", "3" }

这是我的查询:

    var checkPurchaseAccount = vcEntities.VcUserAccountTbls.Where(x =>
 !strPurchaseFormNoList.Contains(x.FormNo))

如何选择列表中不包含在表格中的表格编号?

【问题讨论】:

    标签: entity-framework list contains


    【解决方案1】:

    您正在寻找“Except”扩展。

    var reject_list= vcEntities.VcUserAccountTbls.Where(p =>strPurchaseFormNoList.Contains(p.FormNo))
    var checkPurchaseAccount = vcEntities.VcUserAccountTbls.Except(reject_list);
    

    【讨论】:

    • 感谢您的回复,所以我们不能使用一个查询来做到这一点?
    • 我尝试了您的解决方案,但它返回的表格编号包含在表格中而不是在列表中,我希望相反地从列表中返回,而不是在表格中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多