Is this Where condition in Linq-to-sql join correct?
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)
.
精彩评论