Search found 1 match

by potato
Tue 16 Aug 2022 00:56
Forum: Entity Developer
Topic: "Specified cast is not valid" when using enum type as primary key
Replies: 1
Views: 7991

"Specified cast is not valid" when using enum type as primary key

Setting the type of a table's primary key to an enum type causes "Update Model From Database" to fail with the error "Specified cast is not valid".

Reproduction with Entity Developer 7:
  1. Create the following MySQL table:

    Code: Select all

    CREATE TABLE `TestTable` (
        `Id` INT(10) NOT NULL AUTO_INCREMENT,
        PRIMARY KEY (`Id`) USING BTREE
    )
    COLLATE='utf8mb4_unicode_ci'
    ENGINE=InnoDB;
  2. Create a new EF Core model using default settings (database first, adding TestTable to the model, etc)
  3. Add a new enum type using default settings
  4. Change the type of TestTable.Id to the new enum type
  5. Click Model->Update Model From Database
  6. Click next
"Specified cast is not valid."