使EF映射字节数组为二进制而不是varbinary [英] make EF map byte array to binary instead of varbinary
本文介绍了使EF映射字节数组为二进制而不是varbinary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
默认情况下,POCO对象中的c#数据类型byte []被映射到sql type varbinary。可以使用dataannotations或流利的API将其映射到二进制类型吗?
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。
推荐答案
我已经找到了答案。可以通过以下方式使用Fluent API:
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();
}
这篇关于使EF映射字节数组为二进制而不是varbinary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文