2013-04-22 68 views
0

我想將下面的簡單SQL查詢更改爲LINQ,我該如何更改它?想要將SQL查詢更改爲LINQ

select * from table1 where isPaid = 'true' and Id in (select Id from table2 where EmployeeId = 12) 

與此相似?

from pa in db.PaymentAdvices 
where pa.IsPaid == true 
orderby pa.PaidDate descending 
select pa; 

回答

0

這裏代碼的LINQ to SQL:

from t1 in table1 
join t2 in table2 on t1.Id equals t2.Id 
where t2.EmployeeId = 12 
select t1 

希望有用!

+0

謝謝,但我已經編輯了我問題,請你重新檢查一下嗎? – bnil 2013-04-22 07:37:37

+0

它返回不同於SQL查詢記錄的記錄。 – bnil 2013-04-22 07:41:51

0

如果字段isPaid有數據類型爲布爾

from t1 in table1 
join t2 in table2 on t1.Id equals t2.Id 
where t2.EmployeeId = 12 and t1.isPaid == true 
select t1 

如果字段isPaid有數據類型爲字符串

from t1 in table1 
join t2 in table2 on t1.Id equals t2.Id 
where t2.EmployeeId = 12 and t1.isPaid.Equals("true") 
select t1