title: "Implicit conversion from data type nvarchar(max) to varbinary is not allowed" error when storing data using EF6
body: <p>I have two model classes - both have a <code>byte[]</code> field for storing a PDF file.</p>
  
  <p>In the database the two model classes correspond to two tables - both with a <code>varbinary(max)</code> column.</p>
  
  <p>For the one model class, I can easily persist to SQL Server, however for the other class + table I get the error </p>
  
  <blockquote>
    <p>Implicit conversion from data type nvarchar(max) to varbinary is not allowed</p>
  </blockquote>
  
  <p>The two classes and tables are basically similar - except for the names.</p>
  
  <p>I've looked at a lot of answers for for this error, but cannot find any that use EF6. I've created the database tables manually and the classes as well - so no auto-generation involved.</p>
  
  <p>Hope someone can help me past this error.</p>
  
  <p>Thanks in advance</p>
  
  <p>Tried changing column type from <code>varbinary(max)</code> to <code>nvarchar(max)</code>.</p>
  
  <p>Tried deleting table and creating from scratch</p>
  
  <pre><code>//Pdf 
     [Table("SelfBillings")]
  public class SelfBilling
  {
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public long Id { get; set; }
  
      public string OwnerId { set; get; }
  
      public long BookingId { set; get; }
  
      public long SelfBillingNumber { set; get; }
  
      public DateTime Date { get; set; }
  
      public DateTime PeriodStart { set; get; }
  
      public DateTime PeriodEnd { set; get; }
  
      public decimal PeriodDays { get; set; }
  
      public decimal PeriodHours { get; set; }
  
      public decimal RentalAmount { get; set; }
  
      public decimal RentalAmountTotal { get; set; }
  
      public decimal VatAmount { get; set; }
  
      public decimal TotalAmount { get; set; }
  
      public decimal TotalAmountInclVat { get; set; }
  
      //Pdf             
      public byte[] Attachment { set; get; }        
  }
  
  //Database table
  CREATE TABLE [dbo].[SelfBillings]
  (
      [Id] [BIGINT] IDENTITY(1,1) NOT NULL,
      [OwnerId] [VARBINARY](128) NOT NULL,
      [BookingId] [BIGINT] NOT NULL,
      [SelfBillingNumber] [BIGINT] NOT NULL,
      [Date] [DATETIME2](7) NOT NULL,
      [PeriodStart] [DATETIME2](7) NOT NULL,
      [PeriodEnd] [DATETIME2](7) NOT NULL,
      [PeriodDays] [DECIMAL](10, 2) NOT NULL,
      [PeriodHours] [DECIMAL](10, 2) NOT NULL,
      [RentalAmount] [DECIMAL](10, 2) NOT NULL,
      [RentalAmountTotal] [DECIMAL](10, 2) NOT NULL,
      [VatAmount] [DECIMAL](10, 2) NOT NULL,
      [TotalAmount] [DECIMAL](10, 2) NOT NULL,
      [TotalAmountInclVat] [DECIMAL](10, 2) NOT NULL,
      [Attachment] [VARBINARY](MAX) NULL
  ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  GO
  
  //Mapping
  modelBuilder.Entity&lt;SelfBilling&gt;().ToTable("SelfBillings");
  </code></pre>
  
  <p>I expect to have a record created in table <code>SelfBillings</code>.</p>