Linq query with Array in where clause?

前端 未结 4 996
无人共我
无人共我 2020-12-28 16:23

I have searched for this, but still can\'t seem to get this to work for me. I have an array of Id\'s associated with a user (their Organization Id). These are placed in an

4条回答
  •  滥情空心
    2020-12-28 17:09

    It would be something like this, OrgIds.ToList.Contains(p.OrginizationID)

    Though really I would do it more like this:

    var OrgIds = (from oh in this.Database.OrganizationsHierarchies
                       join o in this.Database.Organizations on oh.OrganizationsId equals o.Id
                       where (oh.Hierarchy.Contains(@OrgId))
                          || (oh.OrganizationsId == Id)
                       select o.Id);
    List query = (from p in this.Database.Personnels
                                where (OrgIds.Contains(p.OrigizationID)
                                select p).ToList();
    

    That way the final query to get personnel will execute containing the combined query from both.

提交回复
热议问题