Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
uniqueidentifier与bigint实体框架c#代码优先不兼容_C#_Entity Framework_Guid_Entity Framework Migrations_Int64 - Fatal编程技术网

uniqueidentifier与bigint实体框架c#代码优先不兼容

uniqueidentifier与bigint实体框架c#代码优先不兼容,c#,entity-framework,guid,entity-framework-migrations,int64,C#,Entity Framework,Guid,Entity Framework Migrations,Int64,我的EF代码中首先有这个实体 public class Equipment { public Int64 Id { set; get; } public string Name { set; get; } public string Model { set; get; } public string Factory { set; get; } public DateTime SubmitDateTime {

我的EF代码中首先有这个实体

 public class Equipment
    {
        public Int64 Id { set; get; }
        public string Name { set; get; }
        public string Model { set; get; }
        public string Factory { set; get; }
        public DateTime SubmitDateTime { set; get; }
        public GUID OrganizationId { set; get; }
    }
我把它改成了

 public class Equipment
    {
        public Int64 Id { set; get; }
        public string Name { set; get; }
        public string Model { set; get; }
        public string Factory { set; get; }
        public DateTime SubmitDateTime { set; get; }
        public Int64 OrganizationId { set; get; }
    }
但是在运行之后,我得到了以下错误:

An exception of type 'System.Data.SqlClient.SqlException' occurred in EntityFramework.dll but was not handled in user code

Additional information: Operand type clash: uniqueidentifier is incompatible with bigint
下面是我的迁移方法:

 public class MigrationsConfiguration : DbMigrationsConfiguration<DataContext>
    {

        public MigrationsConfiguration()
        {
            this.AutomaticMigrationDataLossAllowed = true;
            this.AutomaticMigrationsEnabled = true;
        }



    }
公共类迁移配置:DbMigrationsConfiguration
{
公共迁移配置()
{
this.AutomaticMigrationDataLossAllowed=true;
this.AutomaticMigrationsEnabled=true;
}
}

我的数据库中有大量数据。因此,我无法删除它以再次生成它。那么,我如何修复此错误?

通过三个步骤,我更改了它: 第一 我在实体中添加了另一列

public GUID OrganizationId { set; get; }
public int64 OrganizationId2 { set; get; }
public int64 OrganizationId2 { set; get; }
第二 我删除了实体中的guid列

public GUID OrganizationId { set; get; }
public int64 OrganizationId2 { set; get; }
public int64 OrganizationId2 { set; get; }
最后一步 最后我重新命名了我的新专栏

public int64 OrganizationId { set; get; }

您的组织表中有数据吗?您不能这样做,错误很明显。组织表将GUID作为主键,设备中的OrganizationId正在引用它。现在您正在将其更改为bigint,而它不知道该做什么。任意更改的一个简单方法是使用新数据库重新开始。让EF创建表,然后从旧数据库加载它们。您需要首先更改组织表中的OrganizationId列,用bigint填充它们,然后更新设备表,使其使用新值。您需要准备表格、删除外键等@DavidBrowne-Microsoft正如我所说,我的数据库中有大量数据,您对编写SQL脚本感到满意吗?这就是为什么我问您对SQL脚本是否满意的原因。我打算提出同样的建议,但还有一个额外的步骤:您需要在父表和子表中填充列。你没有这样做,因为你有数据,这是非常重要的一步。