Index created on views do not get scaffolded properly
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
调研方向
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 内容生成。
描述
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:
- The Oracle provider returns a
DatabaseViewcontaining correctly namedDatabaseIndexobjects and the correct columns. RelationalScaffoldingModelFactorypreserves the name in the EF index metadata:index.Nameis non-null.- The materialized-view entity is mapped using
ToView(...), with no table mapping. RelationalIndexExtensions.GetDatabaseName()returnsnullwhenGetTableName()is null.CSharpDbContextGenerator.ttusesindex.GetDatabaseName()directly as the namedHasIndexargument, resulting inHasIndex(..., 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
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
dotnet/efcore 的其他 Issue
-
customer-reported
难度 4/5 3-5 天 新手友好度 54/100
维护者通常 2 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
维护者通常 2 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
维护者通常 2 天内回复
-
Regression in 11.0: replacing an owned instance or re-adding an entity with the same key sets unchanged OnAdd properties to null可能已有人在做 @seragAhmed 今天认领。 未关闭
难度 4/5 3-5 天 新手友好度 48/100
维护者通常 2 天内回复
-
customer-reported
难度 5/5 一周以上 新手友好度 35/100
维护者通常 2 天内回复
相似的 Issue
-
bug emitter:client:csharp
难度 2/5 1-3 小时 新手友好度 84/100
microsoft/typespec#12572 · 1 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
needs-area-label
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 2 天内回复
-
AWS Lambda: KeyNotFoundException drops HTTP-triggered transactions when allowAllHeaders is disabled未关闭bug
难度 2/5 1-3 小时 新手友好度 70/100
newrelic/newrelic-dotnet-agent#3949 · 1 条评论 ·
维护者通常 1 天内回复
-
area-networking
难度 2/5 1-3 小时 新手友好度 78/100
dotnet/aspnetcore#70545 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 87/100
维护者通常 1 天内回复