-
Notifications
You must be signed in to change notification settings - Fork 127
Description
I agree with request #415 because as @guy-lud mention, attributes on DTOs are extremely awkward. I opened this as a separate issue because I think this may not work within the existing ClassMap scheme. I want to define are property handlers within the DTO constructor. This makes it easier to organize and keep the logic tied to the DTO.
I would like to define the property handlers like this.
[Map("CompleteTable")]
private class StringToDateClass : BaseEntity<StringToDateClass>
{
[Primary]
public Guid SessionId { get; set; }
public string ColumnDate { get; set; }
public StringToDateClass()
{
Map(p => p.ColumnDate).Convert<DateTime, string>(o => o.ToString("M'/'d'/'yyyy h:mm:ss tt"));
Map(p => p.ColumnDate).Convert<string>(o => DateTime.Parse(o, CultureInfo.InvariantCulture));
}
}
This modification fixed the three unit tests that were failing:
TestSqlConnectionCrudConversionFromStringToDateTime2
TestSqlConnectionCrudConversionFromStringToDateTime
TestSqlConnectionCrudConversionFromStringToDate
I modified the function factories (FunctionFactory.cs) to recognize BaseEntity as well as adding two helper classes to enable calling and caching these converters: EntityPropertyConverter, EntityPropertyMap
The current manner by which the property handlers are defined is quite awkward because you have to create a separate disjoined class for the handler operators (get, set). This way the handlers are defined as lambda directly in the class.
I think this could be added as part of the @guy-lud ClassMap request.