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.

  • The data types varchar and varbinary(max) are incompatible in the add operator. while trying to create stored procedure
  • SQL Server: Can the same table exist in multiple schemas
  • Three CTE Questions
  • Query vs. C# method to retrieve database metadata
  • Difference between Composite Non-clustered Index and Non-clustered Include - Index tree architecture difrence
  • BULK INSERT 4866 and 7301
  • .NET Folder Permission Issue
  • Combine 2 queries into 1
  • Select Post Tags with Dapper dot net
  • Entity framework very slow to load for first time after every compilation
  • C# SQLConnection pooling
  • How to call a SQL Server procedure using Entity Framework 6
  • One Solution collect form web for “make EF map byte array to binary instead of varbinary”

    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();          
            }
    
    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.