I am having a problem returning a default DateTime
value from a complex Linq-to-Sql
query.
Hopefully the following simplified example shows the
users.Select(u =>
new MyDomainObject(
u.Id,
u.Transactions
.Where(t => false) // empty results set
.Select(t => t.TransactionTime)
.Any() ?
u.Transactions
.Where(t => false) // empty results set
.Select(t => t.TransactionTime) // TransactionTime is DATETIME NOT NULL
.OrderByDescending(x => x)
.FirstOrDefault() : // I want DateTime.MinValue (or SqlDateTime.MinValue)
DateTime.MinValue
)
);
This will supply DateTime.MinValue
if there are no transactions available for that object.