efcore.pg icon indicating copy to clipboard operation
efcore.pg copied to clipboard

Missing metadata namespace when scaffolding

Open ajruckman opened this issue 5 years ago • 4 comments

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

ajruckman avatar Dec 17 '20 15:12 ajruckman

Thanks, we should move this public-facing enum (and others) to Microsoft.EntityFrameworkCore.Metadata.

roji avatar Jan 26 '21 15:01 roji

Am going to do this for 6.0 without patching to 5.0 because of the breakage potential (existing scaffolded migrations/model snapshots).

roji avatar Feb 08 '21 14:02 roji

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.

roji avatar Jun 10 '21 14:06 roji

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.

roji avatar Nov 04 '21 16:11 roji

Punting as https://github.com/dotnet/efcore/issues/25493 was punted on the EF side.

roji avatar Oct 15 '22 18:10 roji