-
Notifications
You must be signed in to change notification settings - Fork 2k
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
How to upgrade use of GetColumnName() method #4024
Comments
I had basically the same loop in my code, since I was not using the multiple mapping that the caused the function to be obsolete, I was able to add the line below. var table = Microsoft.EntityFrameworkCore.Metadata.StoreObjectIdentifier.Create(entityType,
Microsoft.EntityFrameworkCore.Metadata.StoreObjectType.Table); and then call foreach (var entity in modelBuilder.Model.GetEntityTypes())
{
var table = Microsoft.EntityFrameworkCore.Metadata.StoreObjectIdentifier.Create(entityType,
Microsoft.EntityFrameworkCore.Metadata.StoreObjectType.Table);
if (table != null)
{
foreach (var property in entity.GetProperties())
{
if (property.GetColumnName(table.Value).EndsWith("Json") && property.ClrType == typeof(string))
{
property.SetColumnType("jsonb");
}
}
}
} Obviously this will not continue to work if you do the double mapping thing described, (and have different column names for the same property), but for most use cases , including yours since you are migrating and won't have the double mapping thing, it will work just fine. The |
Wording for provided example does not make it seem like and example "Use the following code to get the column name for a specific table:" see [https://github.com/dotnet/efcore/issues/28983]
Note for triage: I believe that prior to EF7, |
Looks like this simpler alternative also works:
Funny that this breaking change is expected to be reverted again. 🙄 I still don't understand why it was considered necessary in the first place. |
I'm upgrading an application from ASP.NET Core 3.1 to 6.0. Reading the migration documents, I found this:
https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-5.0/breaking-changes#getcolumnname-obsolete
And I'm using that method here:
This doesn't compile anymore. The migration document has a code sample that doesn't look right to me. I don't want to look up anything in "Users" here but I need the column of a table. (Are there other columns, too?!) The documentation of the method itself is not helpful as it does not explain what I should pass as parameter.
How can I make that code work again with the current EF version? I want that method back and I don't understand why it was removed. It has always worked perfectly for me. This change is not an improvement for me.
EF Core version: 6.0
Database provider: PostgreSQL
Target framework: .NET 6.0
Operating system: Windows 10, Linux
IDE: Visual Studio 2022
The text was updated successfully, but these errors were encountered: