问题
By default c# data type byte[] in POCO object is mapped to sql type varbinary. Is it possible to map it to binary type using dataannotations or fluent API?
Thanx.
回答1:
I have found the answer myself. It can be done using Fluent API the following way
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<MyEntity>().Property(x => x.BinaryProperty).HasMaxLength(LengthOfBinaryField).IsFixedLength();
}
来源:https://stackoverflow.com/questions/29062144/make-ef-map-byte-array-to-binary-instead-of-varbinary