我有两张表--如下所示
#^ int国家#^int,int#^int#^int
Car \ID,int,Name,varchar,CountryID,int,FK到国家
使用EF,我有以下查询。
List<int> listOfCountries = new List<int> { 1,2,3 };
var query = (
from country in context.Countries.AsNoTracking()
join car in context.Cars.AsNoTracking() on new { CountryID = country.ID}
equals new { CountryID = cars .CountryID }
where listOfCountries.Contains(prv.CountryID)
select car);还有其他方法可以代替工会吗?如果国家id不等于(1),然后过滤(4,5)中的car id,这是如何实现的?谢谢。
发布于 2016-06-06 06:22:35
如果我正确理解你的问题,这可能是:
List<int> listOfCountries = new List<int> { 2,3 };
List<int> listOfCarIds = new List<int> { 4,5 };
var query = from car in context.Cars.AsNoTracking()
where car.Country.Id = 1 || (listOfCountries.Contains(car.Country.Id) && listOfCarIds.Contains(car.Id))https://stackoverflow.com/questions/37650647
复制相似问题