Closed 0Lucifer0 closed 1 year ago
It is more provider specific problem and i need more details.
Planning to build a small proof project this weekend so it will help to answer all those questions 😀
It will be very helpful and i'll prepare fix for that quickly because i don't know why conversions in this case was broken. Anyway i think workaround can be simple if you define converter Something like that:
MappingSchema.Default.SetConverter<currency, int>(c => (int)currency)
here an example : https://github.com/erwan-joly/BulkCopyProofOfIssue
tried
MappingSchema.Default.SetConverter<Currency, int>(c => (int)c);
and
MappingSchema.Default.SetConverter<Currency, string>(c => nameof(c));
didn't change anything
Conversion is simple:
MappingSchema.Default.SetConverter<Currency, DataParameter>(c =>
new DataParameter("", c.ToString().ToLower())
);
seems to works fine with a converter :) just had to make it to snake case instead of lower to work with all my enums
for those who are still looking for how to do it, I got it like this.
public enum PriorityLevel {...}
public class DataContext : DbContext
{
...
static DataContext()
{
var nameTranslator = NpgsqlConnection.GlobalTypeMapper.DefaultNameTranslator;
NpgsqlConnection.GlobalTypeMapper.MapEnum<PriorityLevel>();
MappingSchema.Default.SetDefaultFromEnumType(typeof(EdgeType), typeof(string));
MappingSchema.Default.SetConverter<EdgeType, string>(c => nameTranslator.TranslateMemberName(c.ToString()));
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.HasPostgresEnum<PriorityLevel>();
}
...
}
Closing as it looks like all questions resolved.
Some extra notes:
MappingSchema.Default
with new AddMappingSchema
configuration API in latest release: you can configure separate mapping schemaGlobalTypeMapper
anymore in npgsql 7, check this issue for help
when trying to bulk copy a list of entities containing Enum parameters (that are represented by enum in postgres) i'm getting this message. (here for the enum currency)