I get a null reference error when assigning anonymous type data to the dto property.
DTO is basically contains string ProductName, DateTime ProductDate
I am writing a linq query to assign data to these fields:
...
action = new
{
Id = (Guid?)paa.Id ?? null,
Product= (from p in cx.Products
join s in cx.Station on p.Id equals s.ProductId
where p.IsDeleted == false
&& p.PlanStartDate != null
&& p.IsDeleted == false
select new
{
p.PlanStartDate,
p.Code
}
).FirstOrDefault(),
}
And some group rules. After that, i want to assign this property.
ProductDate= s3.Key.action.Product.PlanStartDate,
ProductCode= s3.Key.action.Product.Code,
But I'm getting nullreferenceexception. However, when I only use PlanStartDate property, everything is fine. But I cant solve this.