Check name for null before attempting to rewrite

And annotate the plugin for nullability.

Fixes #179
This commit is contained in:
Shay Rojansky
2023-01-13 13:30:20 +01:00
parent c0bcefe529
commit 81d512004d
8 changed files with 134 additions and 81 deletions

View File

@@ -468,6 +468,24 @@ public class NameRewritingConventionTest
Assert.Null(entityType.GetTableName());
}
[Fact]
public void Foreign_key_without_name_because_over_view()
{
var model = BuildModel(b =>
{
b.Entity<Blog>();
b.Entity<Post>().ToView("posts_view");
b.Entity<Post>().HasOne(x => x.Blog).WithMany().HasForeignKey(x => x.BlogId);
});
var postEntityType = model.FindEntityType(typeof(Post))!;
Assert.Null(postEntityType.GetTableName());
Assert.Collection(
postEntityType.GetForeignKeys().Select(fk => fk.GetConstraintName()),
Assert.Null,
Assert.Null);
}
private IEntityType BuildEntityType(Action<ModelBuilder> builderAction, CultureInfo culture = null)
=> BuildModel(builderAction, culture).GetEntityTypes().Single();