Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.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
C# 在其他地方使用的ce its在本次迁移中没有更改,并且@trailmax也将其视为原因,它是属性和特定的ExpressiveAnnotationsattributes_C#_Entity Framework_Entity Framework Migrations - Fatal编程技术网

C# 在其他地方使用的ce its在本次迁移中没有更改,并且@trailmax也将其视为原因,它是属性和特定的ExpressiveAnnotationsattributes

C# 在其他地方使用的ce its在本次迁移中没有更改,并且@trailmax也将其视为原因,它是属性和特定的ExpressiveAnnotationsattributes,c#,entity-framework,entity-framework-migrations,C#,Entity Framework,Entity Framework Migrations,我真正的酒吧课是这样的 public class Bar { //This was not touched in ages, some even before adding the first migration [Required] [AssertThat(@"<Condition>", ErrorMessage = "Please revise the name")] public string Name { get; set; } } 公共类栏

我真正的酒吧课是这样的

public class Bar
{
    //This was not touched in ages, some even before adding the first migration
    [Required]
    [AssertThat(@"<Condition>", ErrorMessage = "Please revise the name")]
    public string Name { get; set; }
}
公共类栏
{
//这在很久以前就没有被触及过,有些甚至在添加第一次迁移之前
[必需]
[断言(@“”,ErrorMessage=“请修改名称”)]
公共字符串名称{get;set;}
}

我注释掉了
AssertThat
属性,猜猜看,所有不应该存在的更改都消失了。

好吧,再看一下@trailmax,我想尝试一些东西,一个我没有包含在问题中的信息,因为它在其他地方使用,所以被视为原因,在这次迁移中没有更改,@trailmax也将其视为原因,即属性和
ExpressiveAnnotations
attributes

我真正的酒吧课是这样的

public class Bar
{
    //This was not touched in ages, some even before adding the first migration
    [Required]
    [AssertThat(@"<Condition>", ErrorMessage = "Please revise the name")]
    public string Name { get; set; }
}
公共类栏
{
//这在很久以前就没有被触及过,有些甚至在添加第一次迁移之前
[必需]
[断言(@“”,ErrorMessage=“请修改名称”)]
公共字符串名称{get;set;}
}

我注释掉了
AssertThat
属性,猜猜看,所有不应该存在的更改都消失了。

尝试过,尝试过删除数据库,然后再次执行所有迁移,结果相同。尝试过,尝试过删除数据库,然后再次执行所有迁移,结果相同。数据库是正确的,正如问题和@Ronan对答案的评论中所述,我放弃了db,迁移也得到了同样的结果。数据库是正确的,正如问题和@Ronan对答案的评论中所述,我放弃了db,迁移也得到了同样的结果。我不介意投反对票,但是,请解释投反对票的原因,如果问题不清楚,或者手头问题的原因很明显,请告诉我答案。在任何其他迁移中,
bar.Name
是否有任何更改?在一个案例中,我确实发现手动修改的迁移脚本产生了非常类似的错误。另外,您使用的是什么版本的SQL Server(假定这是SQL Server)?我在我的开发机器上使用SQLServer2008R2时遇到了问题。但当升级到2014年时,问题就解决了away@trailmax它的SQL Server 2012和SQL Azure,没有酒吧。名称是在首次迁移之前添加的,之后从未更改,谢谢你的回答和博客。我不介意否决票,但是如果问题不清楚,请解释否决票的原因,或者问题的原因很明显,那么请告诉我答案。在任何其他迁移中,
bar.Name
是否有任何更改?在一个案例中,我确实发现手动修改的迁移脚本产生了非常类似的错误。另外,您使用的是什么版本的SQL Server(假定这是SQL Server)?我在我的开发机器上使用SQLServer2008R2时遇到了问题。但当升级到2014年时,问题就解决了away@trailmax它的SQL Server 2012和SQL Azure,没有任何条。名称是在初始迁移之前添加的,之后从未更改,谢谢你的回答和博客。我打赌如果你现在返回这个属性并尝试添加迁移,它会告诉你模型没有变化,迁移也没有必要。@trailmax我就是这么想的,但是当我取消注释代码时,问题返回了,当我有时间时,我会尝试更多地调查它。我打赌如果你现在返回此属性并尝试添加迁移,它会告诉你模型中没有更改,也不需要迁移。@trailmax我就是这么想的,但是当我取消对问题返回的代码的注释时,我会在有时间时尝试更多地调查它。
//Code from Trailmax Tech Blog
public class MigrationDecompressor
{
    public string ConnectionString { get; set; }

    public String DecompressMigrationFromSource(IMigrationMetadata migration)
    {
        var target = migration.Target;
        var xmlDoc = Decompress(Convert.FromBase64String(target));
        return xmlDoc.ToString();
    }

    public String DecompressDatabaseMigration(String migrationName)
    {
        var sqlToExecute = String.Format("select model from __MigrationHistory where migrationId like '%{0}'", migrationName);

        using (var connection = new SqlConnection(ConnectionString))
        {
            connection.Open();

            var command = new SqlCommand(sqlToExecute, connection);

            var reader = command.ExecuteReader();
            if (!reader.HasRows)
            {
                throw new Exception("Now Rows to display. Probably migration name is incorrect");
            }

            while (reader.Read())
            {
                var model = (byte[])reader["model"];
                var decompressed = Decompress(model);
                return decompressed.ToString();
            }
        }

        throw new Exception("Something went wrong. You should not get here");
    }

    /// <summary>
    /// Stealing decomposer from EF itself:
    /// http://entityframework.codeplex.com/SourceControl/latest#src/EntityFramework/Migrations/Edm/ModelCompressor.cs
    /// </summary>
    private XDocument Decompress(byte[] bytes)
    {
        using (var memoryStream = new MemoryStream(bytes))
        {
            using (var gzipStream = new GZipStream(memoryStream, CompressionMode.Decompress))
            {
                return XDocument.Load(gzipStream);
            }
        }
    }
}

        //Inside Program.cs

        var decompresser = new MigrationDecompressor
        {
            ConnectionString = "<connection string>"
        };

        var databaseSchemaRecord = decompresser.DecompressDatabaseMigration("<migration name>");
        using (var streamWriter = new StreamWriter(@"D:\LastMigration.xml"))
        {
            streamWriter.Write(databaseSchemaRecord);
        }
<Property Name="NewProperty" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" />
.
.
.
<ScalarProperty Name="NewProperty" ColumnName="NewProperty" />
.
.
.
<Property Name="NewProperty" Type="nvarchar(max)" Nullable="true" />
public class Bar
{
    //This was not touched in ages, some even before adding the first migration
    [Required]
    [AssertThat(@"<Condition>", ErrorMessage = "Please revise the name")]
    public string Name { get; set; }
}