Error storing Image in SQL CE 4.0 with ASP.NET MVC 3 and Entity Framework 4.1 Code First

后端 未结 3 1028
难免孤独
难免孤独 2020-12-17 10:02

I\'m trying to store/save an image in an SQL Compact Edition (CE) database.

I declare the field in my Student model as:

[Column(TypeName = \"image\")         


        
3条回答
  •  伪装坚强ぢ
    2020-12-17 10:27

    The way to specify no maximum length using the MaxLength data annotation is to provide no maximum value. For example:

    [MaxLength]
    public byte[] Photo { get; set; }
    

    The SQL Compact provider will then map the property to "image" and EF validation will recognize that there is no max length specified and so does not need to be disabled. If you want to be explicit about mapping to an "image" column then you can do this:

    [Column(TypeName = "image")]
    [MaxLength]
    public byte[] Photo { get; set; }
    

    which will produce the same result when using SQL Compact.

提交回复
热议问题