Dotnet Core 3.1 版本的 RelationalMetadataExtensions.Relations()

huangapple go评论70阅读模式
英文:

Dotnet core 3.1 version of RelationalMetadataExtensions.Relations()

问题

我们正在使用 <b>RelationalMetadataExtensions</b> 在dotnet core 2.0中读取关系型数据库特定的元数据。我们计划升级应用程序到3.0版本。但是在dotnet core 3.0中,<b>RelationalMetadataExtensions</b>已经过时。以下是dotnet core 3.1中以下代码的行为:

// 以下代码仅适用于MySQL。
var items = _context.Model.GetEntityTypes();
foreach (var item in items)
{
    //RelationalMetadataExtensions.Relational([NotNullAttribute] this IEntityType entityType)
    if (item.Relational() is RelationalEntityTypeAnnotations extensions)
    {
        extensions.Schema = database;
    }
}
英文:

We are reading relational database specific metadata using <b>RelationalMetadataExtensions</b> in dotnet core 2.0. We have planned to upgrade the app into 3.0. But <b>RelationalMetadataExtensions</b> is obsolute in the dotnet core 3.0. What will be the dotnet core 3.1 behavior of the following code

  // Following code only working for mysql.
        var items = _context.Model.GetEntityTypes();
        foreach (var item in items)
        {
            //RelationalMetadataExtensions.Relational([NotNullAttribute] this IEntityType entityType)
            if (item.Relational() is RelationalEntityTypeAnnotations extensions)
            {
                extensions.Schema = database;
            }
        }

答案1

得分: 3

根据更新日志,您的代码将无法正常工作。您需要使用扁平化的版本。

不幸的是,问题 214 似乎仍然没有解决。我可以看到已经实现了 GetSchema,但没有找到 SetSchema。您可以提出一个新的 GitHub 请求,看看(如果有的话)它会在什么时候实现。

编辑

在这里检查有一个 SetSchema。向 Ivan Stoev 致以敬意。

提供程序特定的元数据 API 更改

跟踪问题 #214

新行为

提供程序特定的扩展方法将被扁平化:

IProperty.Relational().ColumnName -> IProperty.GetColumnName()
IEntityType.SqlServer().IsMemoryOptimized -> IEntityType.IsMemoryOptimized()
PropertyBuilder.UseSqlServerIdentityColumn() -> PropertyBuilder.UseIdentityColumn()

为什么

这个更改简化了上述扩展方法的实现。

缓解措施

使用新的扩展方法。

英文:

Based on the update log, your code will not work. You will need to use the flattened out versions.

Unfortunately, the issue 214 seems to still be open. I can see the GetSchema has been implemented already, but no SetSchema to be found. You could raise a new GitHub request to see when (if) it's getting there

Edit

There is a SetSchema check here. Kudos to Ivan Stoev.

> Provider-specific Metadata API changes
>
>Tracking Issue #214
>
> New behavior
>
> The provider-specific extension methods will be flattened out:
>
> IProperty.Relational().ColumnName -&gt; IProperty.GetColumnName()
>IEntityType.SqlServer().IsMemoryOptimized -&gt; IEntityType.IsMemoryOptimized()
> PropertyBuilder.UseSqlServerIdentityColumn() -&gt; PropertyBuilder.UseIdentityColumn()
>
> Why
>
> This change simplifies the implementation of the aforementioned extension methods.
>
> Mitigations
>
> Use the new extension methods.

huangapple
  • 本文由 发表于 2020年1月6日 14:47:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/59607795.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定