According to what I have read, the original issue #554 has been addressed by the pull request #605. But it seems that this issue still exists in the latest preview (3.0.0-preview5).
Here is the model and configuration:
publicenumMood{Happy,Sad}publicclassBlog{publicintBlogId{get;set;}publicMoodMood{get;set;}}publicclassBloggingContext:DbContext{publicDbSet<Blog>Blogs{get;set;}// map enum without specifying pgNamestaticBloggingContext()=>NpgsqlConnection.GlobalTypeMapper.MapEnum<Mood>();// it works when specified a correct pgName// static BloggingContext() => NpgsqlConnection.GlobalTypeMapper.MapEnum<Mood>("my.mood");protectedoverridevoidOnConfiguring(DbContextOptionsBuilderoptionsBuilder)=>optionsBuilder.UseNpgsql("Host=my_host;Database=my_db;Username=my_user;Password=my_pw");protectedoverridevoidOnModelCreating(ModelBuildermodelBuilder){// specify a default schemamodelBuilder.HasDefaultSchema("my");modelBuilder.ForNpgsqlHasEnum<Mood>();}}The script generated by dotnet ef migrations script is:
CREATETABLEIF NOT EXISTS "__EFMigrationsHistory" (
"MigrationId"character varying(150) NOT NULL,
"ProductVersion"character varying(32) NOT NULL,
CONSTRAINT"PK___EFMigrationsHistory"PRIMARY KEY ("MigrationId")
);
CREATESCHEMAIF NOT EXISTS my;
CREATESCHEMAIF NOT EXISTS my;
CREATETYPEmy.mood AS ENUM ('happy', 'sad');
CREATETABLEmy."Blogs" (
"BlogId"serialNOT NULL,
"Mood" mood NOT NULL, -- ERROR: type "mood" does not exist. should use my.moodCONSTRAINT"PK_Blogs"PRIMARY KEY ("BlogId")
);
INSERT INTO"__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20190718112346_init', '3.0.0-preview5.19227.1');The expected script to create the my."Blogs" table is:
CREATETABLEmy."Blogs" (
"BlogId"serialNOT NULL,
"Mood"my.moodNOT NULL, -- mood --> my.moodCONSTRAINT"PK_Blogs"PRIMARY KEY ("BlogId")
);And dotnet ef database update will fail with this message:
Failed executing DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE my."Blogs" (
"BlogId" serial NOT NULL,
"Mood" mood NOT NULL,
CONSTRAINT "PK_Blogs" PRIMARY KEY ("BlogId")
);
Npgsql.PostgresException (0x80004005): 42704: type "mood" does not exist
I have attached the project so that you can examine this issue.
ConsoleApp.zip
According to what I have read, the original issue #554 has been addressed by the pull request #605. But it seems that this issue still exists in the latest preview (3.0.0-preview5).
Here is the model and configuration:
The script generated by
dotnet ef migrations scriptis:The expected script to create the my."Blogs" table is:
And
dotnet ef database updatewill fail with this message:I have attached the project so that you can examine this issue.
ConsoleApp.zip