0

Hi I'm using entity framework code first to create my database

[Range(1, 100)]
[DataType(DataType.Currency)]
public decimal Price { get; set; }

The problem is when the table is created the "Price" field takes up the data type decimal(18, 2) and if I tried to change the data type to money the SQL Server did not allowed me to do so.

Is there a way so that I may define a specific data type? That my sql server data type is assigned to money by default?

Or is there another way to solve this? I'm using .Net Framework 4. EF 4.4.0.0 on visual studio 2010 ultimate and MS SQL Server 2008 Express sp2.

Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
  • Beware of the math when calculating with money though: http://stackoverflow.com/questions/582797/should-you-choose-the-money-or-decimalx-y-datatypes-in-sql-server – Andreas May 25 '13 at 16:29
  • @Andreas The article you mentioned explains well which data type to use but it don't says anything about EF. – samaun ibna faiz May 28 '13 at 13:42
  • Also this article is available here on stackoverflow that treats the topic of money and entity framework: http://stackoverflow.com/questions/4829776/generate-money-type-fields-using-code-first-ef-ctp5 – Andreas May 29 '13 at 06:04

1 Answers1

1

Here is the solution of the part to choose a diffrent sql server data type

[Column(“BlogDescription", TypeName="ntext")] 
public String Description {get;set;}

Also u can choose a different column name to use in your database. here the Description column in the entity is actually stored as BlogDescription column in the database table with MS SQL SERVER data type ntext.