select * from (select p.* from RL_WJ_Paper p
where P.pExpired>2015-10-29 and p.pStatus=2) b
LEFT JOIN
(
select * from RL_WJ_AnswerSheet
where CreatedBy=70192
) t ON t.asPID=b.PID
WHERE T.ASID IS NULL
query = from q in query
join q1 in query1
on q.PID equals q1.asPID
into q2
from q1 in q2.DefaultIfEmpty()
where q2 == null
select q;
我在代码中这样写
其中 query 是sql中的b 表
query1 是sql中的T表
但是我这个查出来数据为零
sql查出来还有一条数据
看代码你这linq q2是对象吧 不应该是q2.ASID ==null 吗?
那个q2.ASID 掉不出来
@聆听雨的愁:
var list = db.t_project.Include("projecttypes").Where(o => o.begindate <=date && (string.IsNullOrEmpty(city) || o.city.Contains(city)) && o.status == true && adminusercitylist.Contains(o.city))
.ToList(); 我们用ef时条件联接查询一般用的是这种形式,单纯的linq联接查询
//联接 var temp = from usertemp in userlist join sch in Schlist on usertemp.SchID equals sch.SchID select new { Id = usertemp.ID, Name = usertemp.Name, Age = usertemp.Age,Schname=sch.SchName };
http://www.cnblogs.com/jingch/p/4832640.html这是我以前写的linq博客,你参考吧
q2还是一张表吧
@聆听雨的愁: 你怎么搞那么复杂干嘛,直接写sql语句不就完了吗,不一定非要用linq。再说了 按这个模子也能写出来了呀;
//联接 var temp = from usertemp in userlist join sch in Schlist on usertemp.SchID equals sch.SchID select new { Id = usertemp.ID, Name = usertemp.Name, Age = usertemp.Age,Schname=sch.SchName };
//你把变量换一下就行啦 这已经分解的很清楚了
var b = from a in list where a.ID > 0 select a;
var t = from c in list where c.Sex == "1" select c;
var temp = from a1 in b join c1 in t on a1.ID equals c1.ID select new {ID=a1.ID,name=c1.Name,sex=c1.Sex};