I'm trying to query data of the form with LINQ-to-EF:
class Location {
string Country;
string City;
string Address;
…
}
by looking up a location by the tuple (Country, City, Address). I tried
var keys = new[] {
new {Country=…, City=…, Address=…},
…
}
var result = from loc in Location
where keys.Contains(new {
Country=loc.Country,
City=loc.City,
Address=loc.Address
}
but LINQ doesn't want to accept an anonymous type (which I understand is the way to express tuples in LINQ) as the parameter to Contains().
Is there a "nice" way to express this in LINQ, while being able to run the query on the database? Alternately, if I just iterated over keys and Union()-ed the queries together, would that be bad for performance?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…