4
I have the following LINQ query:
var source = from em in query
select new
{
Id = em.UniqueID,
Data = em.Data == DateTime.MinValue ? "" : em.Data.Value.ToString("dd/MM/yy HH:mm")
};
The estate Data
is the type Nullable<DateTimeOffset>
and so Resharper shows me a warning saying:
Possible System.Invalidoperationexception
And give me a hint to change that query to
var source = from em in query
let dateTimeOffset = em.Data
where dateTimeOffset != null
select new
{
Id = em.UniqueID,
Data = dateTimeOffset == DateTime.MinValue ? "" : dateTimeOffset.Value.ToString("dd/MM/yy HH:mm")
};
It seems to me that the let
creates a variable in the middle of the query, that’s right?