Missing metadata namespace when scaffolding
Hi, one of our databases has a timestamp index, and when I scaffold this database, the generated DbContext has a line like this:
entity.HasIndex(e => e.affected_date, "ix_affected_date")
.HasSortOrder(new[] { SortOrder.Descending });
However this doesn't compile:
TearsDBContext.cs(494, 43): [CS0103] The name 'SortOrder' does not exist in the current context
These are all of the imported namespaces:
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
For this to compile the class also needs this:
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
I am using
- Microsoft.EntityFrameworkCore 5.0.1
- Microsoft.EntityFrameworkCore.Design 5.0.1
- Microsoft.EntityFrameworkCore.SqlServer 5.0.1
- Npgsql.EntityFrameworkCore.PostgreSQL 5.0.1
Thanks, we should move this public-facing enum (and others) to Microsoft.EntityFrameworkCore.Metadata.
Am going to do this for 6.0 without patching to 5.0 because of the breakage potential (existing scaffolded migrations/model snapshots).
Reverting #1669 in #1879, since that fix breaks earlier migrations when upgrading to 6.0 (e.g. https://github.com/dotnet/efcore/issues/24877).
Scaffolding should be fixed by https://github.com/dotnet/efcore/issues/25046.
dotnet/efcore#25046 ended up not taking care of literals, which is what's needed here (SortOrder.Descending). https://github.com/dotnet/efcore/issues/25493 tracks doing that, and is planned for 7.0.
Punting as https://github.com/dotnet/efcore/issues/25493 was punted on the EF side.