EntityFramework - contains query of composite key

前端 未结 7 1578
渐次进展
渐次进展 2020-11-22 06:06

given a list of ids, I can query all relevant rows by:

context.Table.Where(q => listOfIds.Contains(q.Id));

But how do you achieve the sa

7条回答
  •  没有蜡笔的小新
    2020-11-22 06:44

    in Case of composite key you can use another idlist and add a condition for that in your code

    context.Table.Where(q => listOfIds.Contains(q.Id) && listOfIds2.Contains(q.Id2));
    

    or you can use one another trick create a list of your keys by adding them

    listofid.add(id+id1+......)
    context.Table.Where(q => listOfIds.Contains(q.Id+q.id1+.......));
    

提交回复
热议问题