0

When building a class and I want an nvarchar(255) I can decorate the property with:

[StringLength(255)]
public string Name { get; set; }

What can I do for a byte[] to make sure the column that gets created is a binary(16) in the database?

Thanks.

Cyberdrew
  • 1,832
  • 1
  • 19
  • 39

1 Answers1

0

You would use the following:

[MaxLength(16)]
public byte[] SomeByteArray { get; set; }
  • I have not tested this but I am assuming it will make a varbinary(16), I am needing a binary(16) – Cyberdrew Nov 06 '15 at 02:36
  • Looks like you are going to have to use the fluent syntax in this case: http://stackoverflow.com/questions/29062144/make-ef-map-byte-array-to-binary-instead-of-varbinary –  Nov 06 '15 at 17:24
  • According to [this answer](http://stackoverflow.com/a/32556396/4265041) it is possible using data annotation attributes. – Steven Rands Sep 06 '16 at 13:52