相关疑难解决方法(0)

我们可以使用代码优先迁移来运行SQL脚本吗?

我们可以使用代码优先迁移来运行sql脚本吗?

我是新手代码,如果我想在迁移的update-database命令之前将我的更改保存到SQL脚本文件,是否可能?

如果可能,请提供完成工作的步骤.此外,如果生成脚本,那么我是否可以使用迁移运行该脚本?

c# sql-server asp.net-mvc entity-framework asp.net-mvc-4

44
推荐指数
4
解决办法
3万
查看次数

Code First从int迁移到Guid主键问题

我正在尝试将我的代码第一个ID列从"int"更改为"Guid",并且在尝试运行迁移时,我收到消息:

Identity column 'CustomFieldId' must be of data type int, bigint, smallint, tinyint, or decimal or numeric with a scale of 0, and constrained to be nonnullable.
Run Code Online (Sandbox Code Playgroud)

我正在定义这样的列:

public partial class CustomField : BaseEntity
{

    [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public Guid CustomFieldId { get; set; }
Run Code Online (Sandbox Code Playgroud)

在CustomFieldMapping.cs中映射它,如下所示:

public CustomFieldMapping()
{
    //Primary key
    HasKey(t => t.CustomFieldId);

    //Constraints 
    Property(t => t.CustomFieldId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
Run Code Online (Sandbox Code Playgroud)

并且生成的迁移正在尝试执行此操作:

public override void Up()
{
    DropForeignKey("dbo.CustomField", "CustomFormId", "dbo.CustomForm");
    DropForeignKey("dbo.CustomData", "CustomFieldId", "dbo.CustomField");
    DropForeignKey("dbo.CustomForm", "ParentFormId", "dbo.CustomForm");
    DropIndex("dbo.CustomField", new[] { "CustomFormId" });
    DropIndex("dbo.CustomForm", new[] { …
Run Code Online (Sandbox Code Playgroud)

entity-framework-6

5
推荐指数
1
解决办法
4559
查看次数