I'm writing a program that uses Entity Framework and linq. The problem is with the query arInvArea
and especially in the where
clause. In WithSwimmingPool
there are zero values and therefore I get null reference exception. How can I catch such exception in the where
clause. Other solutions in Stackoverflow didn't help me. Thanks
private ObjectContactsRow CreateNewRow(AreaInventory arInv)
{
// Here in the where clause I get exception ! WithSwimmingPool is from type bool
var arInvArea = arInv.Area.Where(p => p.WithSwimmingPool)
.Select(p => p.Units(ReportDate))
.FirstOrDefault();
return new ObjectContactsRow()
{
areaSize = arInvArea
};
}
public partial class Area
{
public bool WithSwimmingPool => AreaArt.AreaUnit_ID == "SWMP";
}
public class ObjectContactsRow
{
public double areaSize { get; set; }
public override object[] GetExcelRow()
{
var index = 0;
Row[index++] = areaSize;
return Row;
}
}