I am looking for some suggestion over best practice (considering Memory and CPU time) to handle Nullable<T> fields returned from a stored procedure on using Linq2Sql.
Please consider the following scenario and limitations:
- I want to avoid using fieldValue.HasValue check everywhere in the code. Thus, I need to replace all
Nullable<T>with normal properties (esp DateTime, Double, Int) with some default value. - I am expecting to read ~1million objects with ~20 fields of Nullable type.
- Memory and CPU usage is an important consideration.
- The requirement is to get result from stored proc in an object (not DataRow), and thus using Linq2Sql.
Please share your opinion or experience over handling a similar situation.
Thanks for your interest.
Best Solution:
Don’t allow SQL to return NULL Values.
The easiest way to do this is to not allow the columns themselves to be null, but if that isn’t a possibility then you can do an ISNULL(field, defaultvalue) in the query that you are using to return the data.
Next Best Solution:
default(type)value for the field.There is no way to not check every value.