string strCityId = condition.CityId.ToString();
string startChar = strCityId + ",";
string endChar = "," + strCityId;
string inChar = "," + strCityId + ',';
var result = this.DAO.AllDatas.Where(u => u.SidelineCities == strCityId ||
u.SidelineCities.StartsWith(startChar) ||
u.SidelineCities.EndsWith(endChar) ||
u.SidelineCities.Contains(inChar));
if (condition.JobId > 0)
{
//这里startChar2变量,故意加了一个2,与上面的startChar分别开.
//因为如果变量名一样,linq在反射的时候,会将用后面的覆盖前面的.
//也就是说,前面的查询,查的都是下面的值.
string strJobId = condition.JobId.ToString();
string startChar2 = strJobId + ",";
string endChar2 = "," + strJobId;
string inChar2 = "," + strJobId + ',';
result = result.Where(u => u.SidelinesWantToDo == strJobId ||
u.SidelinesWantToDo.StartsWith(startChar2) ||
u.SidelinesWantToDo.EndsWith(endChar2) ||
u.SidelinesWantToDo.Contains(inChar2));
}