0

I have configured various entities in my DbContext class to convert the enum value to a string when saving to the database eg.

modelBuilder.Entity<TestObject>(builder =>
{
   builder.ToTable("TestObject", "test");
   builder.Property(x => x.MyEnum).HasConversion<string>();
}

However all of these enum values are being saved as the numeric value behind the enum.

I've tried checking the strings aren't being truncated by the max lengths on the columns in the database but the enum string values are definitely all valid lengths.

At this point I'm not sure where else to check, any help is appreciated!

mb1231
  • 308
  • 3
  • 16

1 Answers1

0

The issue was I was using a stored procedure for the insert and didn't realise I was passing the enum value to the SQL parameter in as MyTestEnum.TestValue.

Passing in MyTestEnum.TestValue.ToString() as the SQL parameter fixed the issue.

mb1231
  • 308
  • 3
  • 16