090603 T LINQ的一个小问题

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));
}

上一篇:ModelAndView详解


下一篇:删除 PostgresSql 数据库 报错:有 N 个其它会话正在使用数据库 的解决方案