How do I get fluent nhibernate to create a varbinary(max) field in sql server

czk picture czk · Jul 8, 2009 · Viewed 11.1k times · Source

How can I get fluent nhibernate to create a varbinary field in a sql server 2005 table that uses a field size of varbinary(max)? At the moment I always get a default of varbinary(8000), which isn't big enough as i'm going to be storing image files.

I've tried using CAstle.ActiveRecord but havent had any success yet.

 [ActiveRecord]
 public class MyFile : Entity
{
    public virtual string FileName { get; set; }
    public virtual string FileType { get; set; }
    public virtual int FileVersion { get; set; }
    public virtual int FileLength { get; set; }

    [Property(ColumnType = "BinaryBlob", SqlType = "VARBINARY(MAX)")]
    public virtual byte[] FileData { get; set; }   
}

Been failing at finding a solution for hours now, so thanks in advance

czk

Answer

Dan Fitch picture Dan Fitch · Jul 8, 2009

I'm not sure why your ActiveRecord example is not working, but there you might try setting the length of the column.

With Fluent NHibernate, you should be able to do

Map(x => x.FileData)
    .WithLengthOf(2147483647)