I'm using Entity Framework Code First to query my SQL Server database. I'm also using code migrations to keep it up to date.
When I use the decimal type, the underlying columns are created with a precision/scale of 18,2. For one particular column (exchange rate) I would like to increase this to 18,6.
I'd like to add an attribute to my class that will instruct EF to use the specified decimal precision, as in the following example :
public class Transaction
{
[Key]
public int ID { get; set; }
...
[DisplayName("Exchange Rate")]
[DecimalPrecision(18, 6)]
public decimal? ExchangeRate { get; set; }
}
What I do not want to do is update the OnModelCreating
function as suggesting in this question
Over here I found a potential solution, but I then discovered that code won't compile as it is based on pre-release functionality that was then removed.
An alternative is proposed here, but that looks way complicated, and perhaps before I wade in I thought I might ask if an alternative exists? EF is moving so fast it's hard to keep up with the evolutions, perhaps I missed something.
OnModeCreating
function? – Richard Deeming Nov 30 '12 at 17:17