我正在尝试将实体添加到SQL CE 4,它具有byte []类型的属性.从msdn我发现只有图像类型可以容纳大文件(在我的情况下,它们不是那么大,但仍然超过二进制类型8000字节的限制).
这是模型:
这是模型:
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; } }
我也有从DbContext派生的类,当我使用它时这样的东西
library.Tabs.Add(tab);//tab of type TabModel,File is array with length equals 12000 library.SaveChanges();//throws exception
错误:
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’.”
我试图在属性上使用MaxLength属性,并将错误更改为“不支持长度超过8000的二进制clumn”.
似乎EF将列映射到二进制类型而不是图像.如何解决这个问题?
解决方法
请参阅此博客文章:
http://erikej.blogspot.com/2011/04/saving-images-to-sql-server-compact.html – 您需要禁用验证作为解决方法.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。