Index created on views do not get scaffolded properly

未关闭
#39,616 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
csharp
领域
database

调研方向

Start with the reported path through RelationalIndexExtensions.GetDatabaseName() and CSharpDbContextGenerator.tt; the issue says view-mapped entities have no table name, so the generated HasIndex call gets a null name despite index metadata retaining it. Trace the existing design-time scaffolding tests for indexes on views and add coverage for the reported materialized-view case. Done means scaffolding preserves the index name and the generated context model loads successfully.

由索引模型根据 Issue 内容生成。

描述

customer-reported
Bug description

@roji @ErikEJ

This is a followup on original issue https://github.com/dotnet/efcore/issues/37345
Since that issue is closed, I couldn't reopen it.

I understand that the Oracle scenario was identified earlier in https://github.com/dotnet/efcore/issues/37345 as a separate issue. We have retested it with an Oracle EF Core 11 development build, and the null-index-name problem still reproduces.

Actual behavior and impact

Applying scaffolding using above table, materialized view, and index on the materialized view, the generated configuration still contains:

modelBuilder.Entity<MatViewDemo1>(entity =>
{
    entity.HasNoKey().ToView("MAT_VIEW_DEMO_1");

    entity.HasIndex(e => e.StringCol1, null);
});

This is not only missing metadata: accessing the generated context's Model throws:

System.ArgumentNullException: Value cannot be null. (Parameter 'name')
   at EntityTypeBuilder<TEntity>.HasIndex(..., String name)
Investigation

Boundary logging shows:

  1. The Oracle provider returns a DatabaseView containing correctly named DatabaseIndex objects and the correct columns.
  2. RelationalScaffoldingModelFactory preserves the name in the EF index metadata: index.Name is non-null.
  3. The materialized-view entity is mapped using ToView(...), with no table mapping.
  4. RelationalIndexExtensions.GetDatabaseName() returns null when GetTableName() is null.
  5. CSharpDbContextGenerator.tt uses index.GetDatabaseName() directly as the named HasIndex argument, resulting in HasIndex(..., null).

This appears to be a gap at the shared relational/design-time code-generation boundary, rather than incorrect Oracle index discovery.

Request

Could you please investigate and fix the scaffolding path so that a index supplied for a view-mapped entity produces valid configuration and preserves its name?

For the example in the https://github.com/dotnet/efcore/issues/37345, the expected configuration would be:

entity.HasIndex(e => e.StringCol1, "MAT_VIEW_DEMO_1_INDEX1");
Your code
Please find the complete scenario in https://github.com/dotnet/efcore/issues/37345
Stack traces

Verbose output

EF Core version

11.0.0

Database provider

No response

Target framework

No response

Operating system

No response

IDE

No response

主要语言
C#
星标
14.8k
派生
3.4k
平均合并
3 天 18 小时
30 天内合并 PR
159

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

dotnet/efcore 的其他 Issue

查看 dotnet/efcore 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。