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.

1
  • 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... Commented Mar 15, 2015 at 23:25

1 Answer 1

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();          
        }
Sign up to request clarification or add additional context in comments.

1 Comment

Can also be done using data annotation attributes as per this answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.