Skip to content

Can't create list of enum type column #823

@artfulsage

Description

@artfulsage

Hi. I have a problem with list of enum type column.

public enum Labels : short
{
  Label1 = 1,
  Label2 = 2,
  Label3 = 3,
}

public class Item
{
  public int Id { get; set; }
  public List<Labels> Labels { get; set; }
}

In migration:

 migrationBuilder.CreateTable(
  name: "Item",
  columns: table => new
  {
    Id = table.Column<int>(nullable: false),
    Labels = table.Column<List<Labels>>(nullable: true)
  },
  constraints: table =>
  {
    table.PrimaryKey("PK_Item", x => x.Id);
  });

In database after applying migration there is a table:

CREATE TABLE public."Item" (
    "Id" integer NOT NULL,
    "Labels" smallint[]
);

If I map Enum as said here https://www.npgsql.org/efcore/mapping/enum.html I have this error on saving data

42804: column "Labels" has type smallint[], and expression - labels[] (translation)

And if I don't map Enum I have this error on saving data

The CLR array type System.Collections.Generic.List`1[Labels] isn't supported by Npgsql or your PostgreSQL. If you wish to map it to an PostgreSQL composite type array you need to register it before usage, please refer to the documentation.

So please tell me is there a bug in library or in its usage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions