Index created on views do not get scaffolded properly

オープン
#39,616 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
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時間
マージ済み PR(30日)
159

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

dotnet/efcore のほかの issue

dotnet/efcore の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。