这两句sql能用linq写出来吗
DELETE d FROM Plan a inner JOIN dbo.Contract c ON a.ID=c.ID INNER JOIN dbo.ContractSub d ON c.SupID=d.ID WHERE c.MType=3 AND a.ID=" + aid
UPDATE d SET d.Pay=c.MPay FROM Plan a inner JOIN dbo.ContractDraft c ON a.ID=c.AID INNER JOIN dbo.ContractSub d ON c.SupID=d.ID WHERE c.MT=2 AND a.ID=" + aid
------解决方案--------------------var plan = (from a in db.Plan
join c in db.Contract
on a.ID equals c.ID
join d in db.ContractSub
on c.SupID equals d.ID
where c.MType==3 && a.ID==aid
select a)
.Take(1)
.FirstOrDefault();
if(result != null)
{
db.Plan.DeleteObject(plan);
db.SaveChanges();
}
更新类似
------解决方案--------------------只能先查出来,再更新/删除,LINQ不支持update delete关键字。
第二句如果查出来的不止一条数据,可以最后一次性调用SaveChanges。
------解决方案--------------------var query=from a in Plan
join c in Contract on a.ID equlas c.ID
join d in ContractSub on c.SupID equlas d.ID
where c.MType==3 && a.ID==aid