Bug #65001 Trying to customize column precision in Code First does not work.

Submitted: 16 Apr 2012 22:43 Modified: 28 Sep 2012 18:57
Reporter: Fernando Gonzalez.Sanchez Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version: OS:Any
Assigned to: Fernando Gonzalez.Sanchez CPU Architecture:Any

[16 Apr 2012 22:43] Fernando Gonzalez.Sanchez
Description:

As per reported by a user in http://forums.mysql.com/read.php?38,520733,520733#msg-520733

Trying to customize precision does not work.

How to repeat:

Create a class 

public class Movie
  {
    public int ID { get; set; }
    public string Title { get; set; }
    public DateTime ReleaseDate { get; set; }
    public string Genre { get; set; }
    public decimal Price { get; set; }
  }

Override its precision using the OnModelCreating method:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
      base.OnModelCreating(modelBuilder);
      modelBuilder.Entity<Movie>().Property(x => x.Price).HasPrecision(18, 2);
    }

The column Price is generated in the database always with precision (10, 0),

Tested with Connector/NET 6.5.4

The code OnModelCreating works for MSSQL.

Suggested fix:

Make it work like expected:

modelBuilder.Entity<Movie>().Property(x => x.Price).HasPrecision(18, 2);

will generate

create table Movie (
...
   Price decimal( 18, 2 )
}
[28 Sep 2012 18:57] John Russell
Added to changelog for 6.4.6, 6.5.5, 6.6.3: 

Customizing precision by calling the HasPrecision() method within the
OnModelCreating() method in a Code First project would always produce
precision settings (10,2) rather than the specified precision.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.040 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.