0

由于来自客户的奇怪请求,我设法弄清楚如何使用 SQL 查询来实现它,但我无法将它翻译成 LinQ。

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

查询到 LinQ 的翻译是什么?

4

2 回答 2

1

你可以只为Count()函数提供一个谓词

var result = new { 
            Count1 = table1.Count(r => r.attribute1.Contains("value1")), 
            Count2 = table2.Count(r => r.attribute2.Contains("value2")) 
        };  
于 2012-08-01T09:28:17.973 回答
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();
于 2012-08-01T09:10:29.237 回答