| 2/14/2007 10:54:10 PM |
I have several datetime database fields which accept nulls, I have changed these members to nullable (of date) in the appropriate class but get this error whenever I retrieve a record that contains a date:
[InvalidCastException: Invalid cast from 'System.DateTime' to 'System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'.] System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider provider) +864 System.DateTime.System.IConvertible.ToType(Type type, IFormatProvider provider) +36 System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) +433 Wilson.ORMapper.QueryHelper.ChangeType(Object value, Type type) +334 Wilson.ORMapper.Internals.Instance.SetField(EntityMap entityMap, Object entityObject, String member, Object value, CustomProvider provider) +49 Wilson.ORMapper.Internals.Instance.SetObject(IDataRecord data) +316 Wilson.ORMapper.ObjectReader.Read() +251 Wilson.ORMapper.Internals.Context.GetObject(Type objectType, Object objectKey, Boolean firstLevel) +268 Wilson.ORMapper.ObjectSpace.GetObject(Type objectType, Object objectKey) +66 admin_test.Page_Load(Object sender, EventArgs e) +54 System.Web.UI.Control.OnLoad(EventArgs e) +80 System.Web.UI.Control.LoadRecursive() +49 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3743 I've tried everything I can think of but am unable to get this to work. Strangely, I have another project using WORM with datetime fields which I handle in exactly the same way and that one works fine.
Any ideas?
|
| 2/15/2007 2:48:25 PM |
Make sure you remove any nullValue="..." setting you have for these fields in your mapping file. That was the non-generic, pre-.net 2.0, way to handle nulls, using "magic" numbers, and if its there in your mapping file then it means the mapper will still try that technique, which will break your nullable types.
Thanks, Paul Wilson |
| 2/15/2007 3:38:39 PM |
Thanks for your reply Paul.
I don't have any nullValue="" settings in my mappings.config, a sample date attribute would be -
<attribute member="_invoicesent" field="invoice_sent" alias="Invoicesent" />
Which is basically the same as it is in the working project I have.
|