recently, we had to clean the database from all the testing data, when an error similar to the following appeared:
The value “” is not of type “System.Nullable`1[System.DateTime]” and cannot be used in this generic collection
The code I executed was:
IQuery query = DbManager.MySession.CreateQuery(“select max(dateObject.EndDate) from DateDomain dateObject”);
IList<DateTime?> list = query.List<DateTime?>();
When I debugged NHibernate code, I reached to the following AddAll() method in the ArrayHelper class:
152 // NH-specific
153 public static void AddAll(IList to, IList from)
155 foreach (object obj in from)
You can find the explanation of the error here.
Which brings us to the interesting question: why the implementation of IList Add method doesn’t consider the “nullability” of the T object? and why the parameter is of type IList ?!
Am I missing something? should I report it as a bug?