【问题标题】:c# mvc query get values with (not exists, or not in, or foreach)c# mvc query get values with (not exists, or not in, or foreach)
【发布时间】:2018-10-28 18:38:24
【问题描述】:

我有一个选定的用户属性,其值为 int (1,2,3) 我有我的邀请订单模型,其中包含用户 ID (1,2) 我想获得两者之间不同的值。 在这种情况下 3.

order.userSelected 有值(1,2,3) 我的invitationOrder 模型有(Id,IdUser,more...)

我该怎么做? 我不知道如何用 foreach 证明我不想获得模型中没有的值

case "newUsersToAddInvitationOrder":
foreach(var item  in order.userSelected )
{
   int id = item;// userSelected has values 1,2,3  
   //  invitationOrder has IdUser 1 and 2          
   db.InvitationOrder
       .Where(m=>m.IdOrder==order.IdOrder)
       .Where(m=>m.IdUser==id)//I want to get the value that is not in the invitation that value 3,


}

【问题讨论】:

  • 显示一些代码!
  • 问题有点含糊,但如果这两个都是收藏,您可以通过list1?.Where(x => !list2.Contains(x))?.ToArray() 获得它们。假设 list2 不为空
  • 请显示类和样本数据。很难理解你想要什么。

标签: c# .net entity-framework linq


【解决方案1】:

如果我理解正确,你想这样做

order.userSelected.Except(db.InvitationOrder.Where(m=>m.IdOrder==order.IdOrder).Select(m=>m.IdUser));

【讨论】:

    猜你喜欢
    • 2015-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-16
    • 1970-01-01
    • 2015-10-14
    • 1970-01-01
    • 2019-07-15
    相关资源
    最近更新 更多