NHibernate possible bug in IQuery.List<T>()
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: // NH-specific public static void AddAll(IList to, IList from) { foreach (object obj in from) { to.Add(obj); } } 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?! ...