This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Using one of the newer v5 nightly builds i have created an object that i want to save to the database. it has a datetimeoffset field in it. when i unitOfWork.SaveChanges(); i get this: ErrorCode: "ArgumentException"
Message: "Object of type 'System.DateTime' cannot be converted to type 'System.DateTimeOffset'."
StackTrace: "[AppActionCreate: 3/17/2014 5:49:21 PM]: [REQUEST: {EmailAddress:foo@bar.com,Version:1.2.3.4.5,ApplicationName:Name,ApplicationAction:Started,ActionDatetime:0001-01-01T00:00:00.0000000+00:00}] System.ArgumentException: Object of type 'System.DateTime' cannot be converted to type 'System.DateTimeOffset'. at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast) at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr) at System.Reflection.RtFieldInfo.InternalSetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture, StackCrawlMark& stackMark) at System.Reflection.RtFieldInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture) at System.Reflection.FieldInfo.SetValue(Object obj, Object value) at Mindscape.LightSpeed.Model.FieldModel.SetValueSlow(Object target, Object value) at Mindscape.LightSpeed.Model.TypeModel.TimestampCreate(Entity entity) at ..?(Entity ) at ..?(Entity , ICollection Why? i am not using any DateTimes anywhere in my database or my DTOs that i am using. line 161 is my call to unitOfWork.SaveChanges(); |
|
|
Are you using CreatedOn or UpdatedOn tracking with this entity and have you changed the backing field for this to be a DateTimeOffset, perhaps to match up with your database schema?
|
|
|
my database field is a datetimeoffset in sql server 2012. i havent changed anything after dragging the tables from the server explorer. on my table entity, track create and update are both False (i did not change these). my field name in the database is CreatedOn and the field in my table is indeed set to DateTimeOffset. i turned on logging via TraceLogger and didnt see any errors. i also looked at the classes generated and it is showing a DateTimeoffset for the field too hopefully its an easy fix as its preventing me from saving anything new to the database. really liking LightSpeed so far! |
|
|
CreatedOn is a reserved name within LightSpeed and it is a naming convention for indicating that the field will be treated as storage for when the entity was created. The backing field has to be DateTime for this. There is a general description about entity tracking in the docs here: http://www.mindscapehq.com/documentation/lightspeed/Implementing-Storage-Policies-with-LightSpeed/Entity-Tracking You should be able to resolve this by renaming your property and then assigning the Column Name field to be "CreatedOn" to map it back to the database field. Alternatively if you want to retain the property name you can set the generation model to None and then manually create the field with a seperate name, and then a property called CreatedOn which utilizes that field in a partial class. Its the field being named _createdOn which infers the special behaviour.
|
|
|
that fixed it. =) it would be nice to only make CreatedOn reserved if i am using creation tracking (or at least a warning saying that i have a field name thats reserved) |
|