DateTime not converting for some reason

Feb 1, 2012 at 1:42 AM

Hi Ashley and others-
Simol worked the first time for me- no problems whatsoever! Awesome!! I am having a tiny problem- it doesn't want to convert a DateTime field that looks like this:

 1/9/2012 10:57:36 AM

Here's the error I get:
String value '1/9/2012 10:57:36 AM' could not be converted to expected property type 'System.DateTime' for property 'PropertyValues[creationdate]'.

The property it's mapping to in the Class:

        public DateTime creationdate { get; set; }

I did download and build the source using the latest AWS .NET dll,, but I think I was having this problem before I tried that. Any suggestions?

Thanks so much for all your hard work on this, and good luck with your Dynamo project.

Cheers!

 

 

More Detail

Simol.SimolDataException was unhandled

Message=String value '1/9/2012 10:57:36 AM' could not be converted to expected property type 'System.DateTime' for property 'PropertyValues[creationdate]'.

Source=Simol  StackTrace:
at Simol.Core.MappingUtils.StringToPropertyValue(PropertyFormatter formatter, AttributeMapping attributeMapping, String valueString) in C:\code\simol-70792\trunk\src\Simol\Core\MappingUtils.cs:line 175

Feb 1, 2012 at 1:56 AM

Ha! I always do this. Post a question, and it magically causes me to find the solution on my own. For those who have a similar problem, Ashley has documented this very thing:

http://simol.codeplex.com/wikipage?title=Defining%20Object%20Mappings&referringTitle=Documentation

In a section called: Mapping and Formatting Customization

 

So in the above example, I had to change

public DateTime creationdate { get; set; }

to:

[CustomFormat("MM-dd-yyyy hh:mm:ss")]
public DateTime creationdate { get; set; }

Thanks Ashley! Awesome!

Coordinator
Feb 1, 2012 at 2:03 AM

You're welcome! Glad you figured it out from the docs.