PomeloFoundation / Pomelo.EntityFrameworkCore.MySql

Entity Framework Core provider for MySQL and MariaDB built on top of MySqlConnector
MIT License
2.68k stars 382 forks source link

When Pomelo creates 'dotnet ef migrations script', 'decimal type' is output as 'money type'. #1683

Open bluekms opened 2 years ago

bluekms commented 2 years ago

Steps to reproduce

Tutorial: Create a complex data model - ASP.NET MVC with EF Core I am learning the official tutorial.

The issue

class Department
{
    [DataType(DataType.Currency)]
    [Column(TypeName = "money")]
    public decimal Budget { get; set; }
}

original source code

class Department
{
    [DataType(DataType.Currency)]
    public decimal Budget { get; set; }
}

my source code 1

class Department
{
    [DataType(DataType.Currency)]
    [Column(TypeName = "decimal")]
    public decimal Budget { get; set; }
}

my source code 2

original source code, my1, my2 They all produce the same code.

`Budget` money(65,30) NOT NULL
Exception message: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'money(65,30) NOT NULL,
Stack trace: money(65,30) NOT NULL,
        `StartDate` datetime(6) NOT NULL,
        `Inst' at line 8

Further technical details

MySQL version: 8.0.28 Operating system: windows 10 Pomelo.EntityFrameworkCore.MySql version: 6.0.1 Pomelo.EntityFrameworkCore.MySql.Design : 1.1.2 Microsoft.EntityFrameworkCore : 6.0.6 Microsoft.EntityFrameworkCore.Design : 6.0.1

bluekms commented 2 years ago

Maybe it's a snapshot issue. Is there any way to fix that?

KirillKaverin commented 2 years ago

@bluekms the official Microsoft tutorial uses SQL Server LocalDB engine which supports 'money' type (which looks like alias for decimal type). There is no money type in MySQL and MariaDB and that's why there is no such support in Pomelo. Maybe it will be good for Pomelo to detect DataType(DataType.Currency)] attribute and automatically convert such types to decimal.

To make it work for you: 1) Remove [DataType(DataType.Currency)] 2) Remove [Column(TypeName = "money")] or replace it with [Column(TypeName = "decimal(18,2)")]. Check the official MySQL guide for decimal precision and scale (18 and 2 in my case) https://dev.mysql.com/doc/refman/8.0/en/fixed-point-types.html