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!!
i found it
the length attribute should be defined in this case