今天看到代码程序中有这么一段语句(已知userid=1,parentid=0):
[JAjax]
public List GetPurviewByPID(int pid)
{
var q = from o in DB.T_purview
join up in DB.T_userpurview on o.Purviewid equals up.Purviewid
where up.Isdel == false && up.Userid == 1
&& o.Isdel == false && o.Parentid == 0
select o;
return q.Distinct().ToList();
}
我自己翻译成sql语句在数据库中执行:
select distinct o.* from t_purview as o join t_userpurview as up
on(o.purviewid=up.purviewid)
where up.isdel=0 and o.isdel=0 and up.userid=1 and o.parentid=0
请问这样翻译哪里错了? 我写的sql语句在数据库中查出来的结果有11条数据,可是代码运行出来只有7条数据。
只听说sql要翻译linq的,没听说反过来的。为什么呢?因为反过来,你执行下,直接能看linq对应的sql。
http://www.cnblogs.com/songsh96/archive/2009/02/19/1393681.html
已解决,是我搞错了。麻烦大家了。