8000 Decimal truncation on Database First Approach · Issue #1104 · FirebirdSQL/NETProvider · GitHub
[go: up one dir, main page]

8000 Skip to content
Decimal truncation on Database First Approach #1104
Open
cincuranet/FirebirdSql.Data.FirebirdClient
#120
@victorvilella

Description

@victorvilella

Hi guys.

I had a problem with an project with Database First Approach. My app was truncating every decimal's information.

Consider model as:

class Sell 
{
    public int SellerId { get; set; }
    public decimal Total { get; set; }
}

and Context as:

// This context was generated by 'dotnet ef scaffold' command
class MainContext 
{
    public DbSet<Sell> Sells { get;  set; }
    modelBuilder.Entity<Sell>(entity =>
    {
       entity.Property(e => e.Total)
                .HasColumnType("DECIMAL")
                .HasColumnName("TOTAL");
    }
}

When I perform an insert/update operation, it just saves the integer part of decimal.

var sell = new Sell {
    SellerId = 1.
    Total = 323.99
};
context.Sells.Add(sell);
await context.SaveChangesAsync(); // It just saved 323

Looking for a solution I realized the problem was column type generated by ef scaffolding proccess. I adjusted my context as follows:

// This context was generated by 'dotnet ef scaffold' command
class MainContext 
{
    public DbSet<Sell> Sells { get;  set; }
    modelBuilder.Entity<Sell>(entity =>
    {
       entity.Property(e => e.Total)
                .HasColumnType("NUMERIC(10, 3)")
                .HasColumnName("TOTAL");  
      // I changed DECIMAL to NUMERIC with precision present on table's field.
    }
}

I would like to ask to fix this issue and I give my problem and how I solved this problem.

Thanks in advance.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0