2012-08-01 49 views
0

。由於從客戶奇怪的要求翻譯,我設法弄清楚如何使用SQL查詢來實現它 ,但我不能把它翻譯成LINQ的支持。SQL查詢中的LINQ

SELECT (SELECT count(*) FROM table1 where attribute1 like 'value1'), 
     (SELECT count(*) FROM table2 where attribute2 like 'value2') 

什麼翻譯查詢到LinQ?

回答

1

你可以只提供一個謂詞的Count()功能

var result = new { 
      Count1 = table1.Count(r => r.attribute1.Contains("value1")), 
      Count2 = table2.Count(r => r.attribute2.Contains("value2")) 
     }; 
1
var count1 = (from i in table1 where SqlMethods.Like(i.attribute1, "value1") select i).Count(); 
var count2 = (from i in table2 where SqlMethods.Like(i.attribute2, "value2") select i).Count(); 
+0

Thanku,它爲我工作,除了SQL方法,請你告訴我如何替換中的SQL方法? – Anwar 2012-08-01 09:26:23