假设我有一个用户表和一个国家表,例如:
tblUsers
int UserId
int UserCountry
tblCountries
int CountryId
string CountryName
并为每个适当地组织映射等。
如果我有类似 List EligibleCountries 之类的内容,如何创建查询以从国家列表中检索所有用户?
就像是:
DetachedCriteria query = DetachedCriteria.For<Users>();
for(int i = 0; i < EligibleCountries.Count(); i++)
{
query.CreateAlias("Country", "c")
.Add(Restrictions.Like("c.CountryId", EligibleCountries[i]));
}
不会工作,因为用户只在一个国家,那将检查他们是否在所有国家......
我尝试使用 Restrictions.In 但这似乎没有按我想要的方式工作。
我该怎么做才能检索用户,只要他们位于合格国家列表中的国家之一?