How do I map a char property using the Entity Framework 4.1 “code only” fluent API?

前端 未结 5 1267
臣服心动
臣服心动 2020-12-01 15:27

I have an object that has a char property:

public class Product
{
    public char Code
    {
        get;
        set;
    }
}

Entity Frame

5条回答
  •  感情败类
    2020-12-01 16:00

    In Fluent API you can specify the database column data type using the HasColumnType method like this:

    modelBuilder.Entity()   
    .Property(p => p.Code)   
    .HasColumnType("char");
    

    According to Andre Artus' answer here, HasColumnType is available in EF4.1.

    For those using Data Annotations, the ColumnAttribute can accomplish the same thing.

    [Column(TypeName="char")]
    public string Code { get; set; }
    

提交回复
热议问题