在我的mvc项目中使用nhibernate 3作为orm,但我在保存和加载其类型为byte []
的图像时遇到问题public class PersonImage : PersistentObject
{
private string _contentType;
private byte[] _image;
private Person _person;
virtual public string ContentType
{
get { return _contentType; }
set
{
if ( value != null && value.Length > 20)
throw new ArgumentOutOfRangeException("Invalid value for ContentType", value, value.ToString());
_contentType = value;
}
}
virtual public byte[] Image
{
get { return _image; }
set { _image = value; }
}
}
public class PersonImageMap : ClassMap<PersonImage>
{
public PersonImageMap()
{
Schema("personnel");
Id(p => p.Id);
Map(p => p.Image)
.CustomSqlType("varbinary(MAX)")
.Not.Nullable();
Map(p => p.ContentType)
.Not.Nullable();
}
}
问题是我认为这张图片无法正确保存,因为当我加载它时我只能看到图像的一部分而不是整个图像!!
答案 0 :(得分:2)
Map(p => p.Image)
.Length(2147483647)
.CustomSqlType("varbinary(MAX)")
.Not.Nullable();
答案 1 :(得分:0)
我已经使用NHibernate 2.1成功映射了图像(Tablet PC InkPicture控件内容),因此它应该可以在3中工作。属性是字节数组,数据库字段是varbinary(max),但我没有添加任何其他方法映射:
Map(p => p.Image);
就是这样。我怀疑你是在保存和检索整个图像,但是它在UI中以某种方式被裁剪。