I have class Person which has property CardType
public class Person{
protected Person(){}
public Person(CardType cardType){
cardType = CardType;
}
public CardType CardType { get; private set; }
... other properties ommited
}
public class CardType : Enumeration
{
public static CardType Amex = new CardType(1, "Amex");
public static CardType Visa = new CardType(2, "Visa");
public static CardType MasterCard = new CardType(3, "MasterCard");
public CardType(int id, string name)
: base(id, name)
{
}
}
I'm trying to map CardType property using EF Core
public void Configure(EntityTypeBuilder<Person> builder)
{
builder.ToTable("Person");
builder.Property(x => x.CardType);
}
But I'm getting following:
The property 'Person.CardType' is of type 'CardType' which is not supported by current database provider. Either change the property CLR type or ignore the property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
You cannot use custom classes as types for Data properties (they can be used in navigation properties only). You need to use enum:
public enum CardType
{
Default = 0,
Amex,
Visa,
MasterCard
}