Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IProperty.GetColumnName() does not return the sql column name for complex types? #34215

Closed
Wasserwecken opened this issue Jul 12, 2024 · 1 comment

Comments

@Wasserwecken
Copy link

Wasserwecken commented Jul 12, 2024

Im not quite sure but I am expecting the sql column name when calling IProperty.GetColumnName().
This behaviour never stats that but what else should the column name then be? Sorry if im wrong!

I noticed my code failing when I added an entity with a repeated complex type.
The prefix of the column names for the complex type properties is just missing.
I was expecting the same name as in the migration, or in the database.

image

Include your code

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using System.ComponentModel.DataAnnotations.Schema;


using (var ctx = new AppDbContext())
{
    ctx.Database.Migrate();
    ctx.Add(new Item() { Primary = new() { Whatever = "Foo" }, Secondary = new() { Whatever = "Bar" } });
    ctx.SaveChanges();
}


using (var ctx = new AppDbContext())
{
    var type = ctx.Set<Item>().EntityType;
    var props = type.GetFlattenedProperties();
    var names = props.Select(e => e.GetColumnName());

    foreach (var name in names)
        Console.WriteLine(name);

    var mapping = props.ToDictionary(e => e.GetColumnName(), e => e);
}


[ComplexType]
public class Info
{
    public string Whatever { get; set; }
}

public class Item
{
    public int Id { get; set; }
    public Info Primary { get; set; }
    public Info Secondary { get; set; }
}


public class AppDbContext : DbContext
{
    public DbSet<Item> Items { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder builder)
    {
        //builder.LogTo(Console.WriteLine, new[] { RelationalEventId.CommandExecuting }).EnableSensitiveDataLogging();
        builder.UseSqlite(@"Data Source=data.db;");
    }
}

Include provider and version information

EF Core version: 8.0.7
Database provider: Microsoft.EntityFrameworkCore.SQLite
Target framework: .NET 8.0

@Wasserwecken Wasserwecken changed the title IProperty.GetColumnName() for complex types does not return the sql column name? IProperty.GetColumnName() does not return the sql column name for complex types? Jul 12, 2024
@AndriySvyryd
Copy link
Member

Same root cause as #33458

The final column name is calculated in a later stage (when the model is finalized). Unfortunately, with the current convention infrastructure it would be prohibitively slow to calculate this while the model is being built.

Duplicate of #9329

@AndriySvyryd AndriySvyryd closed this as not planned Won't fix, can't repro, duplicate, stale Jul 12, 2024
@AndriySvyryd AndriySvyryd removed their assignment Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants