Hmm... I think I could live with adding fields for local time as well (not in the DB of course).
Can you elaborate a bit what do you mean with virtual properties via typedescriptor?
Edit: added the template modification I tried with previous version (entityAdapter.template)
What I do like about this approach is that it's really nice to use, databinding and all works really nice, no need to add new fields or anything like that. I did not test it that much though, but did not encounter any problems with it either.
<[Foreach EntityField CrLf]>
/// <summary> The <[EntityFieldName]> property of the Entity <[CurrentEntityName]><br/><br/>
/// <[Foreach CustomProperty EntityField]>
/// <[CustomPropertyName]>: <[CustomPropertyValue]><br/><[NextForeach]></summary>
/// <remarks>Mapped on <[ CaseCamel TargetType ]> field: "<[SourceObjectName]>"."<[SourceColumnName]>"<br/>
/// <[ TargetType ]> field type characteristics (type, precision, scale, length): <[SourceColumnDbType]>, <[SourceColumnPrecision]>, <[SourceColumnScale]>, <[SourceColumnMaxLength]><br/>
/// <[ TargetType ]> field behavior characteristics (is nullable, is PK, is identity): <[SourceColumnIsNullable]>, <[IsPrimaryKey]>, <[IsIdentity]></remarks>
public <[If EntityFieldOverrides]>override<[Else]>virtual<[EndIf]> <[TypeOfField]> <[EntityFieldName]>
{
get
{
object valueToReturn = base.GetCurrentFieldValue((int)<[CurrentEntityName]>FieldIndex.<[EntityFieldName]>);
if(valueToReturn == null)
{
valueToReturn = TypeDefaultValue.GetDefaultValue(typeof(<[TypeOfField]>));
}
if (typeof(<[TypeOfField]>) == typeof(System.DateTime))
{
//When reading values, always return datetimes as LocalTime
//DataAdapter reads the values from underlying data structure, so this code is not used when
//enties are being saved.
System.DateTime datetime = (System.DateTime)valueToReturn;
valueToReturn = datetime.ToLocalTime();
}
return (<[TypeOfField]>)valueToReturn;
}
set
{
if (value is System.DateTime)
{
//When any client is updating datetime values, convert them to UTC
SetNewFieldValue((int)<[CurrentEntityName]>FieldIndex.<[EntityFieldName]>, Convert.ToDateTime(value).ToUniversalTime());
}
else
{
SetNewFieldValue((int)<[CurrentEntityName]>FieldIndex.<[EntityFieldName]>, value);
}
}
}<[NextForeach]>