嗨,我寫了這個 sql 查詢,但我想寫 linq 版本 sql 版本
Select CalisanId From Calisanlar Where Lisans=0 INTERSECT (Select CalisanId From Covids)
public List<LisansCovid> GetLisansCovid()
{
using (SirketDBContext context = new SirketDBContext())
{
var result =
(from cal1 in context.Calisanlar
where cal1.Lisans == 0
select cal1.CalisanId)
.Intersect
(from cal2 in context.Covids
select cal2.CalisanId);
//exception return result.ToList();
}}
uj5u.com熱心網友回復:
嘗試以下,未測驗;假設有一個資料庫連接db:
var infoQuery =
(from cal1 in db.Calisanlar
where cal1.Lisans == 0
select cal1.CalisanId)
.Intersect
(from cal2 in db.Covids
select cal2.CalisanId);
var result = inforQuery?.ToList() ?? 0;
或者,lambda 運算式
var infoQuery =
(db.Calisanlar.Where(x => x.Lisans == 0).Select(x => x.CalisanId))
.Instersect(db.Covids.Select(x => x.CalisanId))
UPDATE 假設CalisanID是一個回傳integer 檢查,null如果找到則回傳零。再次,未測驗。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/385975.html
上一篇:JSP頁面中的增量變數
