I'm using NHibernate to store downloads in my MySQL database for an ASP.NET MVC website. I am using to classes. One called Download
for the download itself and one called DownloadContent
for the file itself (so I can load it easier when I just want to get the metadata).
The data class declarations and mappings look like this:
public class Download
{
public virtual string Id { get; set; }
public virtual string OutFileName { get; set; }
public virtual DownloadContent Contents { get; set; }
public virtual string MimeType { get; set; }
public virtual bool DoForward { get; set; }
public virtual string RedirectLink { get; set; }
}
public class DownloadMap : ClassMap<Download>
{
public DownloadMap()
{
Id(x => x.Id);
Map(x => x.OutFileName);
References<DownloadContent>(x => x.Contents);
Map(x => x.MimeType);
Map(x => x.DoForward).Not.Nullable();
Map(x => x.RedirectLink);
}
}
public class DownloadContent
{
public virtual byte[] Data { get; set; }
}
public class DownloadContentMap : ClassMap<DownloadContent>
{
public DownloadContentMap()
{
Id();
Map(x => x.Data).CustomType("BinaryBlob");
}
}
Now, when I try to do like this:
dl.Contents = new DownloadContent { Data = content };
db.session.SaveOrUpdate(content);
I get an NHibernate.MappingException
with the message "No persister for: System.Byte[]". I looked it up with the NHibernate docs and byte[] should map correctly.
What am I doing wrong?