-
Notifications
You must be signed in to change notification settings - Fork 3.3k
RelationalPropertyExtensions.SetColumnName() breaks OwnsOne() model creation in RC1 #22608
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Note for team: I am able to reproduce this on the latest daily and it is a regression from 3.1. Simple repo below. The issue is that the result of calling GetColumnName while the model is being built has changed. In 3.1, it returns @roji Does your naming convention try to get the current names of columns before the model is built? public class Program
{
private static void Main()
{
using var context = new Context();
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
}
}
public class Context : DbContext
{
public DbSet<MainEntity> MainEntities { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseSqlite("Datasource=test.db");
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity<MainEntity>(b =>
{
b.HasKey(b => b.Id);
b.OwnsOne(b => b.FirstOwnedEntity).WithOwner();
b.OwnsOne(b => b.SecondOwnedEntity).WithOwner();
});
var propertyOne = builder.Model
.FindEntityType(typeof(FirstOwnedEntity))
.FindProperty("MainEntityId");
Console.WriteLine($"Reported column name: {propertyOne.GetColumnName()}");
propertyOne.SetColumnName(propertyOne.GetColumnName());
var propertyTwo = builder.Model
.FindEntityType(typeof(SecondOwnedEntity))
.FindProperty("MainEntityId");
Console.WriteLine($"Reported column name: {propertyTwo.GetColumnName()}");
propertyTwo.SetColumnName(propertyTwo.GetColumnName());
}
}
public class MainEntity
{
public int Id { get; set; }
public FirstOwnedEntity FirstOwnedEntity { get; set; }
public SecondOwnedEntity SecondOwnedEntity { get; set; }
}
public class FirstOwnedEntity
{
public int SomeValue { get; set; }
public int PropertyNamingConventionIssue { get; set; }
}
public class SecondOwnedEntity
{
public int AnotherValue { get; set; }
public int PropertyNamingConventionIssue { get; set; }
} |
Setting the column name via SetColumnName() in OnModelCreating() seems to break OwnsOne() entities. This used to work as expected in EF Core 3 (and v5-preview4 I'm pretty sure) but in v5-RC1 the following exception occurs:
When removing the
property.SetColumnName(property.GetColumnName())
the model/schema is created successfully. Oddly enough, when inspecting the database schema there isn't even a column/key named "MainEntityId".Steps to reproduce
To reproduce, run the OwnsOnePropertyNamingConventionRC1 project attached (uses RC1 Nuget packages for EntityFrameworkCore+Sqlite+Npgsql):
OwnsOnePropertyNamingConventionRC1.zip
To compare to old behavior, run the OwnsOnePropertyNamingConvention project attached (uses EF Core 3 packages).
OwnsOnePropertyNamingConvention.zip
Verbose output of
dotnet ef migrations add InitialCreate
is as follows:Further technical details
EF Core version: Version 5.0.0-rc.1.20451.13
Database provider: Microsoft.EntityFrameworkCore.Sqlite + Npgql.EntityFrameworkCore.PostgreSQL
Target framework: .NET Core 3.0
Operating system: Windows 10
IDE: Visual Studio 2019 16.6.5
The text was updated successfully, but these errors were encountered: