c# - Decimal precision and scale in EF Code First -
i'm experimenting code-first approach, i'm find out property of type system.decimal gets mapped sql column of type decimal(18, 0).
how set precision of database column?
the answer dave van den eynde out of date. there 2 important changes, ef 4.1 onwards modelbuilder class dbmodelbuilder , there decimalpropertyconfiguration.hasprecision method has signature of:
public decimalpropertyconfiguration hasprecision( byte precision, byte scale )
where precision total number of digits db store, regardless of decimal point falls , scale number of decimal places store.
therefore there no need iterate through properties shown can called
public class efdbcontext : dbcontext { protected override void onmodelcreating(system.data.entity.dbmodelbuilder modelbuilder) { modelbuilder.entity<class>().property(object => object.property).hasprecision(12, 10); base.onmodelcreating(modelbuilder); } }
Comments
Post a Comment