2

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.

kalan
  • 1,752
  • 4
  • 20
  • 35
  • 1. Do you use code-first or ObjectContext (i assume CF)? 2. Do you use EF-Migrations? In this case you can set the type of the column explicitly... – Stephen Reindl Mar 15 '15 at 23:25

1 Answers1

2

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();          
        }
kalan
  • 1,752
  • 4
  • 20
  • 35
  • Can also be done using data annotation attributes as per [this answer](http://stackoverflow.com/a/32556396/4265041). – Steven Rands Sep 06 '16 at 13:53