It regards Entity Framework 6 but maybe it isn’t related to the version.
I have some class which has Guid Id but by inheritance.
public partial class TestObject : SomeModel<Guid>
{
public TestObject()
{
}
.
.
.
public virtual ICollection<TestObject1> TestObject1s { get; set; }
public virtual ICollection<TestObject2> TestObject1s { get; set; }
}
public abstract class SomeModel<TKey>
{
public TKey Id { get; set; }
}
Right now I would like to change this model to auto generate Id by database. I’ve changed class TestObject by added
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
to
public partial class TestObject : SomeModel<Guid>
{
public TestObject()
{
}
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
.
.
.
public virtual ICollection<TestObject1> TestObject1s { get; set; }
public virtual ICollection<TestObject2> TestObject1s { get; set; }
}
But after executing command add-migration test
I got empty implementation
public partial class test : DbMigration
{
public override void Up()
{
}
public override void Down()
{
}
}
It means that nothing is going to change.
And of course after executing update-Database
it didn’t affect the database.
But if I create a completely new class (whose implementation is the same as TestObject). It works and it affects the database.
public partial class TestObjectNew : SomeModel<Guid>
{
public TestObjectNew()
{
}
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
.
.
.
public virtual ICollection<TestObject1> TestObject1s { get; set; }
public virtual ICollection<TestObject2> TestObject1s { get; set; }
}
Could someone explain this behavior ?
How can I update my class to get auto generation Id by database ?