Here i am using simple list and one of the ageto string column is null
I am check in linq query if value not found then to return null. But value cannot be null error is coming up
var list = new[]
{
new { AgeFrom = "0", AgeTo="24"},
new { AgeFrom = "70", AgeTo= (string)null}
}.ToList();
var result = from r in list
select new EmployeeDTO
{
//AgeFrom Column is int? in DTO
AgeFrom = Convert.ToInt32(r.AgeFrom),
//AgeTo Column is int? in DTO
AgeTo = Convert.ToInt32(r.AgeTo ?? null)
}
nulltoint