kalan
kalan

Reputation: 1832

make EF map byte array to binary instead of varbinary

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.

Upvotes: 2

Views: 2193

Answers (1)

kalan
kalan

Reputation: 1832

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();          
        }

Upvotes: 2

Related Questions