views:

84

answers:

1

Quick question regarding Automapper.

I'm mapping data from an incoming web service, where datetimes fields are not null, but sometimes have the value of DateTime.MinValue as a work-around (I don't own this service so I'm at their mercy I'm afraid). I'm mapping from those objects to Linq To Sql objects created off of a db model I created based on the service description.

Everything is working fine, until I try to submit new rows where DateTime.MinValue is set on the datetime fields. Of course, the solution is to replace DateTime.MinValue with SqlDateTime.MinValue.Value as Sql Server chokes on DateTime.MinValue.

I would like to do this automatically with the mapping... that is, replace this on any datetime fields in the incoming web service call without having to specify on a field by field basis.

Formatters won't do the trick since they only deal with string formatting, and IValueResolver doesn't appear to do what I need either. That appears to be called once per instance of the parent type, not per field within the type (I tried to use it with .ForAllMembers()). Perhaps I did something wrong.

If the NullSubstitute method was generic -- that is, if the signature was something like Substitute<T, Func<T,T>>, then I think I'd be in business.

Documentation / online samples haven't provided much in the way of direction... and while I could start digging through the source, I was hoping someone with more in-depth knowledge of the system could comment (Jimmy?).

I would assume that something like this should be a feature somewhere, but then again, there may be other issues at play which complicate implementing something like this.

Thanks in advance for any assistance.

A: 

Would TypeConverter help?

Arnis L.
Yeah, looks like it would -- don't know how I missed that one! Thanks for the heads up. Will vote this as soon as I can implement / ensure it's doing what I need (which I believe it will).
Ethan J. Brown
I haven't tried it and I confess - I didn't get every detail of Your question, hence - I'm unsure. Anyway - always try to check source code of tools You are using. :)
Arnis L.
Does precisely what I need... thanks for the pointer.
Ethan J. Brown
Glad it helped.
Arnis L.