开发者

linq combined column search

开发者 https://www.devze.com 2023-03-15 19:02 出处:网络
I want to search records which two column combination equals to the parameter, why it does not work? public RDCheck SearchByUserPlusId(string uid)

I want to search records which two column combination equals to the parameter, why it does not work?

public RDCheck SearchByUserPlusId(string uid)
        {
            RDCheckDataContext dc = new RDCheckDataContext(_connString);
            var query = (from r in dc.RDChecks
                         where (r.login + r.id).Equals(uid)
                         select r).FirstOrDefault();
            return query;
        }

for example, one record in table is id:4/login:test So I pass parameter uid=test4 but it r开发者_JS百科eturns null, why?


Use ToString() before the concatenation

public RDCheck SearchByUserPlusId(string uid)
{
       RDCheckDataContext dc = new RDCheckDataContext(_connString);
       var query = (from r in dc.RDChecks
                    where (r.login.ToString() + r.id.ToString()).Equals(uid)
                    select r).FirstOrDefault();
       return query;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消