【发布时间】:2021-09-29 20:17:24
【问题描述】:
我正在尝试将自己的代码写入 ef core migration Up 方法,以将一些静态数据插入表中。简而言之,我想这样做。 INSERT INTO file_type (filetypeid, filetype) VALUES (10, '输出文件');
迁移中的代码
migrationBuilder.InsertData(
"file_type",
new string[] { "filetypeid", "filetype" },
new string[] { "integer", "varchar" },
new object[] { "10", "Output File" });
当我使用上面的代码时,我得到了
当前提供程序不支持迁移数据操作中用于列“file_type.filetypeid”的存储类型“整数”。
如果我省略了数据类型参数 (3) 我会得到
没有实体类型映射到数据操作中使用的表“file_type”。要么在模型中添加对应的实体类型,要么在数据操作中指定列类型。
型号
[Table("file_type")]
public class FileType
{
[Key]
[Column("filetypeid")]
public int FileTypeId { get; set; }
[Column("filetype")]
public string FileTypes { get; set; }
}
【问题讨论】:
标签: c# entity-framework-core database-migration