2016-11-29 17 views
2

當我更新「Microsoft.EntityFrameworkCore.Tools.DotNet」版「1.1.0-preview4」,實體框架已停止生成遷移。身份值生成只能用符號整數性能升級後可用於EF核心1.1

錯誤:

dotnet : System.ArgumentException: Identity value generation cannot be used  
for the property 'UID' on entity type 'SomeEntity' because the property type is 
'Guid'. Identity value generation can only be used with signed integer properties. 

回答

3

的解決辦法是擺脫屬性的[DatabaseGenerated(DatabaseGeneratedOption.Identity)

[Key] 
// [DatabaseGenerated(DatabaseGeneratedOption.Identity)] <-- remove this 
public Guid UID { get; set; } 

和更新模型構建

protected override void OnModelCreating(ModelBuilder modelBuilder) 
{ 
    base.OnModelCreating(modelBuilder); 

    // add this: 
    modelBuilder.Entity<SomeEntity>().Property(p => p.UID).ValueGeneratedOnAdd(); 
} 
相關問題