Search code examples
.net-4.0ef-code-firstsql-server-ce-4entity-framework-5

Image data type in SQL Server Comapct 4 & Code-First Entity Framewwork 5


My Code-First entity column is declared like this:

[Required, DataType("image")]
public byte[] Picture { get; set; }

Validations are turned off:

Configuration.ValidateOnSaveEnabled = false;

And is column type is still varbinary(4000).

When I try to save data, Entity Framework throws an exception:

Byte array truncation to a length of 4000.

How to declare that C# byte[] type should be mapped to image SQL type?

Versions:

SQL Server Compact 4

Entity Framework 5 RC

.NET Framework 4.0


Solution

  • Use this attribute:

    [MaxLength]