What is equal of below sql in LINQ
select MIN(finishTimestamp) AS FromDate, MAX(finishTimeStamp) AS ToDate From Transactions
??
from t in Transactions
select new {
FromDate = ?,
ToDate = ?
}
Thanks
To use multiple aggregates in Linq to SQL, on a table, without grouping, the only way I've found to avoid doing multiple queries, is to make a "fake group":
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)
};
Kinda hacky, but the generated SQL is clean, and by doing so, you make only one query to the database.
You can just do
var transactionDates = from t in Transactions
select t.FinishTimeStamp;
var dates = new {
FromDate = transactionDates.Min(),
ToDate = transactionDates.Max()
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With