You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Migrations: ModelDiffer should find diff on navigations #5155
class Person {
public int Id { get; set; }
public ICollection<Book> Books { get; }
}
class Book {
- public int PersonId { get; set; }+ public int AuthorId { get; set; }
public Person Author { get; set; }
}
class Person {
public int Id { get; set; }
- public ICollection<Book> Books { get; }+ public ICollection<Book> AuthoredBooks { get; }
}
class Book {
- public int PersonId { get; set; }+ public int AuthorId { get; set; }
public Person Author { get; set; }
}
class Person {
public int Id { get; set; }
public ICollection<Book> Books { get; }
}
class Book {
- public int PersonId { get; set; }- public Person Person { get; set; }+ public int AuthorId { get; set; }+ public Person Author { get; set; }
}
It may lead to unexpected renames and alters if you change the type to a property that doesn't convert.
class Person {
- public int Id { get; set; }+ public Guid Guid { get; set; }
public ICollection<Book> Books { get; }
}
class Book {
- public int AuthorId { get; set; }+ public Guid AuthorGuid { get; set; }
public Person Author { get; set; }
}
Before this change, you'd get DropColumn("AuthorId") and AddColumn("AuthorGuid").
After this change, you'll get RenameColumn and AlterColumn.
However, if it went from int to long, the new operations are preferred.
@bricelam if you try to remove an existing FK and add a new FK that points to a different alternate key in the same entity type as the principal side, what would happen? (I think it is a bit ambiguous in the rules you described, but I hope it isn't in the implementation 😄).
Activity
bricelam commentedon Aug 12, 2016
Thinking about how this information can be used, I've can only think of one case:
Are there any others? @ajcvickers @AndriySvyryd @anpete @divega
divega commentedon Aug 12, 2016
@bricelam that is the same one I was aware of.
divega commentedon Aug 12, 2016
FWIW, you mentioned it when you created the original bug #2140.
bricelam commentedon Aug 13, 2016
Oh good, my brain is deterministic over a duration of at least one year.
bricelam commentedon Aug 24, 2016
Here is the rule I've come up with.
If a would-be-added property is part of one or more foreign key constraints, and any of those foreign key constraints...
...then treat it as a renamed column.
Irrelevant information:
Sound good?
bricelam commentedon Aug 24, 2016
Here are some simple cases it covers.
class Person { public int Id { get; set; } public ICollection<Book> Books { get; } } class Book { - public int PersonId { get; set; } + public int AuthorId { get; set; } public Person Author { get; set; } }class Person { public int Id { get; set; } - public ICollection<Book> Books { get; } + public ICollection<Book> AuthoredBooks { get; } } class Book { - public int PersonId { get; set; } + public int AuthorId { get; set; } public Person Author { get; set; } }class Person { public int Id { get; set; } public ICollection<Book> Books { get; } } class Book { - public int PersonId { get; set; } - public Person Person { get; set; } + public int AuthorId { get; set; } + public Person Author { get; set; } }It may lead to unexpected renames and alters if you change the type to a property that doesn't convert.
class Person { - public int Id { get; set; } + public Guid Guid { get; set; } public ICollection<Book> Books { get; } } class Book { - public int AuthorId { get; set; } + public Guid AuthorGuid { get; set; } public Person Author { get; set; } }Before this change, you'd get
DropColumn("AuthorId")andAddColumn("AuthorGuid").After this change, you'll get
RenameColumnandAlterColumn.However, if it went from
inttolong, the new operations are preferred.ajcvickers commentedon Aug 24, 2016
Sounds good to me.
divega commentedon Aug 25, 2016
@bricelam if you try to remove an existing FK and add a new FK that points to a different alternate key in the same entity type as the principal side, what would happen? (I think it is a bit ambiguous in the rules you described, but I hope it isn't in the implementation 😄).
bricelam commentedon Sep 21, 2016
Closing in favor of doing #6582 instead.