什么等于LINQ中的sql以下
select MIN(finishTimestamp) AS FromDate, MAX(finishTimeStamp) AS ToDate From Transactions
Run Code Online (Sandbox Code Playgroud)
??
from t in Transactions
select new {
FromDate = ?,
ToDate = ?
}
Run Code Online (Sandbox Code Playgroud)
谢谢
CMS*_*CMS 38
要在Linq to SQL中使用多个聚合,在表上没有分组,我发现避免进行多个查询的唯一方法是创建一个" 假组 ":
var q = from tr in dataContext.Transactions
group tr by 1 into g // Notice here, grouping by a constant value
select new
{
FromDate = g.Min(t => t.InvoiceDate),
ToDate = g.Max(t => t.InvoiceDate)
};
Run Code Online (Sandbox Code Playgroud)
有点hacky,但生成的SQL是干净的,通过这样做,您只对数据库进行一次查询.
wom*_*omp 18
你可以这样做
var transactionDates = from t in Transactions
select t.FinishTimeStamp;
var dates = new {
FromDate = transactionDates.Min(),
ToDate = transactionDates.Max()
};
Run Code Online (Sandbox Code Playgroud)