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 varb
You need an auto-mapping override:
public class MyFileMapOverride : IAutoMappingOverride
{
public void Override( AutoMapping mapping )
{
mapping.Map( x => x.FileData ).Length( int.MaxValue );
}
}
Since you're using Castle, you can tell it to wire up NHibernate with your mappings in your NHibernateInstaller:
public void Install( IWindsorContainer container, IConfigurationStore store )
{
container.Register( Component.For()
.UsingFactoryMethod( k => BuildSessionFactory() )
.Named( "MySessionFactory" ) );
// Do other stuff...
}
private ISessionFactory BuildSessionFactory()
{
var mappings = AutoMap.AssemblyOf()
.IgnoreBase( typeof(Entity) )
.UseOverridesFromAssemblyOf();
var configuration = ConfigurationUtility
.CreateConfiguration(
"MyDbConnection",
ConfigurationUtility.ForMsSql,
mappings,
NHibernateConfiguration.GetConfigurationPath() );
return configuration.BuildSessionFactory();
}