var data = mockDataDB.Data.AsQueryable()
.Select(x => new ProductDto
{
Id = Convert.ToInt64(x.id), // this might fail because id might be null
Quantity = Int32.TryParse(x.quantity, out int somenumber) ? x.quantity : (int?)null
}
Issue with this code is that x.id
and x.quantity
might be null sometimes, they are both of type string
and id and quantity are type of int64
and int32
..
How could I safely solve this?
Thanks
cheers