【问题标题】:How do I get the TableName from MetaData for .NET 6如何从 MetaData for .NET 6 中获取 TableName
【发布时间】:2022-06-24 04:45:50
【问题描述】:

我在尝试将 TableName 设置为变量时遇到问题。我目前正在尝试从 .NET Core 2.2 版本升级到 .NET 6,但出现此错误

Severity    Code    Description Project File    Line    Suppression State
Error   CS1061  'IEntityType' does not contain a definition for 'Relational' and no accessible extension method 'Relational' accepting a first argument of type 'IEntityType' could be found (are you missing a using directive or an assembly reference?)

有问题的代码是这样的。

TableName = entry.Metadata.Relational().TableName;

【问题讨论】:

    标签: c# entity-framework-core


    【解决方案1】:

    正如错误所述,EntityEntry.MetaData 的方法 Relational() 不再存在,我建议使用 GetTableName() 方法。

    下面的代码应该可以解决你的问题。

    TableName = entry.Metadata.GetTableName();
    

    这个问题也在这里得到了更详细的回答。 Getting metadata in EF Core: table and column mappings

    【讨论】:

      猜你喜欢
      • 2019-01-13
      • 1970-01-01
      • 1970-01-01
      • 2022-06-14
      • 2012-07-03
      • 1970-01-01
      • 2021-12-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多