5
I would like to know how to map my entity using an Enum of the type char
by the Entity Framework, using Fluentapi.
I have the following Enum:
public enum Zona
{
Norte = 'N',
Sul = 'S'
}
And my Entity:
public class Local
{
public Guid RioId { get; set; }
public string Nome { get; set; }
public Zona Zona { get; set; }
}
Configure the entity as follows:
public class LocalMapping : EntityTypeConfiguration<Local>
{
public LocalMapping()
{
ToTable("Local");
HasKey(r => r.LocalId);
Property(r => r.Nome).IsRequired();
Property(r => r.Zona).IsRequired();
}
}
How do I register my Enum Zone as varchar(1)
in the database, so that when saving a Location with North Zone, the character N is saved in the Bank
C# ñ has
enum char
. Better use a code.– Maniero
Follow the solution link Entity Framework Enum Support - Code First
– Pedro Souza