nhibernate 3在保存字节[]时是否有任何问题 [英] does nhibernate 3 have any problem with saving byte []

查看:89
本文介绍了nhibernate 3在保存字节[]时是否有任何问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的mvc项目中,我使用nhibernate 3作为orm,但是我在保存和加载类型为字节[]的图像时遇到问题

in my mvc project im using nhibernate 3 as orm, but i have a problem with saving and loading images which their type is 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();

        }

}

问题是我认为该图像无法正确保存,因为当我加载它时,我只能看到图像的一部分而不是整个图像!

the problem is that i think this image cant be saved correctly because when i load it i just can see a part of image not the whole image!!

推荐答案

我找到了它 在这种情况下,应该定义length属性

i found it the length attribute should be defined in this case

 Map(p => p.Image)
            .Length(2147483647)
            .CustomSqlType("varbinary(MAX)")
            .Not.Nullable();

这篇关于nhibernate 3在保存字节[]时是否有任何问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆