2012-08-01 68 views
0

我创建一个领域:实体框架保存原图

public Byte[] Image { get; set; } 

这将创建一个名为场图像的数据类型varbinary和长度是4000

当我保存一条记录时,它将无法保存,因为图像是保存在varbinary(4000)中的。

如何使它成像数据类型或更大的二进制长度?

我使用sqlserver的CE 4.

回答

0

你必须改变你的属性在数据库中使用image类型的映射。你可以做,要么用数据说明:

[Column(TypeName = "image")] 
public Byte[] Image { get; set; } 

或用流利的API:

modelBuilder.Entity<...>().Property(e => e.Image).HasColumnType("image"); 
+0

错误:类型或命名空间名称“ColumnAttribute”找不到(是否缺少using指令或程序程序集参考?) – Alvin 2012-08-01 10:34:22

+1

添加System.ComponentModel.DataAnnotations.Schema – Alvin 2012-08-01 10:48:33