Tag: where in

LINQ to Entities – where..in具有多列的子句

我正在尝试使用LINQ-to-EF查询表单的数据: class Location { string Country; string City; string Address; … } 通过元组(国家,城市,地址)查找位置。 我试过了 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 } 但LINQ不希望接受匿名类型(我理解是在LINQ中表示元组的方式)作为Contains()的参数。 是否有一种“好”的方式在LINQ中表达这一点,同时能够在数据库上运行查询? 或者,如果我只是迭代密钥和Union() – 一起编写查询,这会对性能有害吗?