make EF map byte array to binary instead of varbinary

你说的曾经没有我的故事 提交于 2019-12-11 01:29:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!