I'm trying to refactor an an existing codebase to use POCO EF. Currently it uses EntityObject
s but there is custom code to "flatten" the mapped objects to POCOs, i.e. for all mapped classes there are currently two related objects, one POCO called MyClass
and one EntityObject
called MyClassEF
which has a single additional method with the signature MyClass Flatten()
. This seems horrible, I know, but it has allowed a fairly straightforward mapping of what are decimal types in the database to double types in the model, because the conversion can take place in the Flatten()
method.
Double types are used in code because they are considerably faster when performing analytical calculations, decimal types are probably used in the database because they seemed like a good idea at the time and the previous hand-rolled ORM didn't have the type-mapping restrictions that EF does. Unfortunately, simply changing the datatype in the database is now impractical because there are so many applications which use it (although most of them still convert the type to double, they still expect it to be decimal in the db).
So, currently I'm looking at modifying my model classes to have something like this :
private double _myDouble;
public double MyDouble { get { return _myDouble; } set { _myDouble = value; }
public decimal MyDouble_asDecimal {
get { return Convert.ToDecimal(_myDouble); }
set { _myDouble = Convert.ToDouble(value); }
}
...which seems fairly unpleasant. Am I missing a blindingly obvious better way to do this?