Enum types with uppercase letters not working
PostgreSQL install on windows.

in my context
static PgSqlDbContext()
{
NpgsqlConnection.GlobalTypeMapper.MapEnum<Mood>("Mood");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ForNpgsqlHasEnum("Mood", new[] { "happy", "sad" });
modelBuilder.Entity<News>().ForNpgsqlHasComment("测试新闻类的注释");
modelBuilder.Entity<News>().ForNpgsqlUseXminAsConcurrencyToken();
base.OnModelCreating(modelBuilder);
}
my model
public class News
{
[Key]
public int NewsId { get; set; }
[StringLength(200)]
public string Titile { get; set; }
public Instant CrateTime { get; set; }
public string[] Tags { get; set; }
public List<string> AlternativeTags { get; set; }
public Mood Mood { get; set; }
}
public enum Mood
{
[PgName("happy")]
Happy,
[PgName("sad")]
Sad,
}

Can you please post the querying C# code?
using (var serviceScope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
{
var context = serviceScope.ServiceProvider.GetRequiredService<PgSqlDbContext>();
context.Database.EnsureDeleted();
context.Database.EnsureCreated(); //throw this exception
}
@roji
when i create database ,throw this exception

modelBuilder.ForNpgsqlHasEnum("mood", new[] { "happy", "sad" });
"happy", "sad" must be lowercase
if i use uppercase and my enum
public enum Mood
{
Happy,
Sad,
}
throw another exception
This is because of #396...
Type names are like other identifiers - if unquoted they are folded to lowercase by PostgreSQL. The problem is that there are people out there specifying the column types as uppercase TEXT, and adding quotes would break their code.
The fix is to only ever quote only user-defined type names (enums, composites in the future), continuing to allow other types to be specified in lower/upper case etc.
@roji but on http://www.npgsql.org/efcore/mapping/enum.html
Still using uppercase,
@quan01994 I don't understand your comment...
I pushed a fix that will allow you to use uppercase enum type names - this will be released in 4.0.1. Until that comes out you have to use lowercase names. I don't see any reason to change the docs since the uppercase issue is fixed...
ok,but in 4.0.0 i need use lowercase ,in next version ,i can use uppercase?
You can use lowercase-only enum names in 4.0.0, but using any uppercase letters will cause a failure. This is fixed in 4.0.1, where you'll be able to use any name you want, uppercase or lowercase.
thanks 👍 : )
Also worth noting that an enum defined:
public Enum Mood{
"Happy",
"NotHappy"
}
must be mapped...
modelBuilder.ForNpgsqlHasEnum("mood", new[] { "happy", "not_happy" });
Is this the expected behavior?
@JNBarnes you're referring to the fact that the .NET enum has Happy and NotHappy, while the PostgreSQL enum needs to have happy and not_happy? If so, you need to read about name translation in the docs.