我正在测试带有MSSQL-Server和Firebird 3.0的EF Core的迁移。
我用几个字段创建一个新表。关键字段具有属性{
"notification": {
/*
Local path or remote url to an image to use as the icon for push notifications.
96x96 png grayscale with transparency.
*/
"icon": STRING,
/*
Tint color for the push notification image when it appears in the notification tray.
6 character long hex color string eg: "#000000"
*/
"color": STRING,
/*
Show each push notification individually "default" or collapse into one "collapse".
Valid values: "default", "collapse"
*/
"androidMode": STRING,
/*
If "androidMode" is set to "collapse", this title is used for the collapsed notification message.
eg: "#{unread_notifications} new interactions"
*/
"androidCollapsedTitle": STRING
}
}
,但是Firebird数据库中的关键字段在迁移过程中不会自动增加。它可以正确地与MS-SQL-Server一起使用。
我使用框架FirebirdSql.EntityFrameworkCore.Firebird 6.6.0。
.ValueGeneratedOnAdd()
答案 0 :(得分:1)
我在http://tracker.firebirdsql.org/browse/DNET-884上找到了解决方案。我必须在DBContext类的OnModelCreating中添加.ForFirebirdUseIdentityColumns()
。现在,我得到了两种数据库类型的自动增量。
现在看起来像这样:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasAnnotation("ProductVersion", "2.2.4-servicing-10062")
.ForFirebirdUseIdentityColumns()
.ForSqlServerUseIdentityColumns();
modelBuilder.Entity<TblTest>(entity =>
{
entity.HasKey(e => e.Id)
.HasName("PK__tblTest");
entity.Property(e => e.Name).IsUnicode(false);
});
}
添加迁移后,我必须在createTable-parameter中的注释中找到我正在使用的第二种数据库类型。就我而言,我使用Firebird添加了迁移,并为SqlServer添加了注释:
migrationBuilder.CreateTable(
name: "tblTest",
columns: table => new
{
ID = table.Column<long>(nullable: false)
.Annotation("Fb:ValueGenerationStrategy", FbValueGenerationStrategy.IdentityColumn)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
Number = table.Column<int>(nullable: true),
Name = table.Column<string>(unicode: false, maxLength: 50, nullable: true),
Date = table.Column<DateTime>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK__tblTest", x => x.ID);
});