Last Updated: February 25, 2016
·
4.438K
· blaiseliu

How to use Entity Framework Code First to create SQL Server money type?

There are a few data types in SQL server that have no corresponding type in C#, like money.

Here is what we are going to do.

In the domain models:

public decimal Price { get; set; }

Please note it has to be decimal. A double will not work.

And in the OnModelCreating method of the fluent api:

Property(i => i.Amount)
    .HasColumnType("Money");

Have a fresh tip? Share with Coderwall community!

Post
Post a tip