LINQ to Entities - where..in clause with multiple columns

后端 未结 12 2045
别那么骄傲
别那么骄傲 2020-12-05 18:23

I\'m trying to query data of the form with LINQ-to-EF:

class Location {
    string Country;
    string City;
    string Address;
    …
}

by

12条回答
  •  执念已碎
    2020-12-05 19:06

    How about:

    var result = locations.Where(l => keys.Any(k => 
                        k.Country == l.Country && 
                        k.City == l.City && 
                        k.Address == l.Address));
    

    UPDATE

    Unfortunately EF throws NotSupportedException on that, which disqualifies this answer if you need the query to run on DB side.

    UPDATE 2

    Tried all kinds of joins using custom classes and Tuples - neither works. What data volumes are we talking about? If it's nothing too big, you could either process it client-side (convenient) or use unions (if not faster, at least less data is transmitted).

提交回复
热议问题