Skip to content

HasPrecision overrides precision set in explicit store type #29600

Closed

Description

@ajcvickers

In the code below, the column type should be decimal(13, 2), but it is actually decimal(24,3).

Reported on #29313 (comment)

public static class Your
{
    public static string ConnectionString = @"Data Source=(LocalDb)\MSSQLLocalDB;Database=AllTogetherNow";
}

public class Blog
{
    public int Id { get; set; }
    public decimal VendorDefectiveQty { get; set; }
}

public class SomeDbContext : DbContext
{
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        => optionsBuilder
            .UseSqlServer(Your.ConnectionString)
            .LogTo(Console.WriteLine, LogLevel.Information)
            .EnableSensitiveDataLogging();

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Blog>()
            .Property(e => e.VendorDefectiveQty)
            .HasPrecision(24, 3)
            .HasColumnType("decimal(13, 2)");
    }
}

public class Program
{
    public static void Main()
    {
        using (var context = new SomeDbContext())
        {
            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            context.SaveChanges();
        }
    }
}
CREATE TABLE [Blog] (
    [Id] int NOT NULL IDENTITY,
    [VendorDefectiveQty] decimal(24,3) NOT NULL,
    CONSTRAINT [PK_Blog] PRIMARY KEY ([Id]));

Activity

  1. self-assigned this
    on Nov 17, 2022
  2. changed the title [-]HasPrecision overrides precision set in explicit type[/-] [+]HasPrecision overrides precision set in explicit store type[/+] on Nov 17, 2022
  3. added this to the 8.0.0 milestone on Nov 18, 2022
  4. added 2 commits that reference this issue on Nov 20, 2022
    e079c3d
    3c96c54
  5. modified the milestones: 8.0.0, on Jan 29, 2023
  6. roji commented on Feb 27, 2023

    @roji
    Member

    Adding providers-beware for provider-facing breaking change (RelationalTypeMappingSource.ParseStoreTypeName)

  7. modified the milestones: , 8.0.0 on Nov 14, 2023
  8. removed their assignment
    on Aug 31, 2024
  9. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions