#c# #entity-framework-core-5.0
Вопрос:
[Table("Items")] public class Item { [Key] public int Id { get; set; } [StringLength(200)] public string ItemName { get; set; } }
EF Core 3.1 и раннее создание кода
migrationBuilder.CreateTable( name: "Items", schema: "dbo", columns: table =gt; new { Id = table.Columnlt;intgt;(nullable: false), ItemName = table.Columnlt;stringgt;(maxLength: 200, nullable: true) }, constraints: table =gt; { table.PrimaryKey("PK_Items", x =gt; x.Id); });
EF Core 5.0 генерирует код с типом БД
migrationBuilder.CreateTable( name: "Items", schema: "dbo", columns: table =gt; new { Id = table.Columnlt;intgt;(type: "int", nullable: false), ItemName = table.Columnlt;stringgt;(type: "nvarchar(200)", maxLength: 200, nullable: true) }, constraints: table =gt; { table.PrimaryKey("PK_Items", x =gt; x.Id); });
Как настроить ModelBuilder, чтобы он не указывал тип в ColumnsBuilder? Type = null позволяет использовать 1 миграцию для нескольких серверов БД. Ручное удаление типа данных из миграции неверно.