开发者

Is this Where condition in Linq-to-sql join correct?

开发者 https://www.devze.com 2022-12-29 00:17 出处:网络
I have the following Iqueryable method to show details of a singl material, p开发者_C百科ublic IQueryable<Materials> GetMaterial(int id)

I have the following Iqueryable method to show details of a singl material,

p开发者_C百科ublic IQueryable<Materials> GetMaterial(int id)
{
    return from m in db.Materials
           join Mt in db.MeasurementTypes on m.MeasurementTypeId equals Mt.Id
           where m.Mat_id equals id
            select new Materials()
            {
              Id = Convert.ToInt64(m.Mat_id),
              Mat_Name = m.Mat_Name,
              Mes_Name = Mt.Name,
            };
}

Any suggestion....


Your where clause should be a boolean expression, like this:

where m.Mat_id == id

You use the keyword equals for joins, but a where clause should use a boolean expression, think of it this way: whatever is in where something it should work as if it were in a if(something).

0

精彩评论

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

关注公众号