I'm trying to add entity to SQL CE 4 which have property of type byte[]. From msdn i have figured out that only image type can hold big files(in my case they not so big, but still over limit of binary type 8000 bytes). Here is the model:
public class TabModel
{
[Key]
public Guid Id { get; set; }
public string Title { get; set; }
public string Subtitle { get; set; }
public string Artist { get; set; }
public string Album { get; set; }
public string Author { get; set; }
public string TabAuthor { get; set; }
public DateTime DateAdded { get; set; }
[Column("file",TypeName="image")]
public byte[] File { get; set; }
public TabModel()
{
Id = Guid.NewGuid();
DateAdded = DateTime.Now;
}
}
I also have class that derived from DbContext and when i use it something like this
library.Tabs.Add(tab);//tab of type TabModel, File is array with length equals 12000
library.SaveChanges();//throws exception
Error:
Validation failed for one or more entities. See 'EntityValidationErrors' property for more details. EntityValidationErrors[0]="The field File must be a string or array type with a maximum length of '4000'."
I have tried to use MaxLength attribute on property and error changes to "Binary clumn with length more 8000 not supported".
It seems like EF maps column to binary type not image. How to fix this?
See this blog post: http://erikej.blogspot.com/2011/04/saving-images-to-sql-server-compact.html - you need to disable validation as a workaround.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With