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

后端 未结 3 1043
难免孤独
难免孤独 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:34

    For those experiencing this problem, Erik Ejlskov Jensen posted a working console application which demonstrates the workaround to this bug. As the OP noted, a key part of the answer is:

        public StudentContext()
        {
            // Required to prevent bug - http://stackoverflow.com/questions/5737733
            this.Configuration.ValidateOnSaveEnabled = false;        
        }
    

    A better solution has been found. Do not disable validation. [Updates from blog post] UPDATE: @DamienGuard, of LINQ to SQL and EF Code First fame, pointed out that a better and more provider agnostic solution is to use MaxLength rather than TypeName = “ntext”.

    UPDATE 2: Using [MaxLength] prevents any validation errors, and disabling validation is not required.

提交回复
热议问题