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

后端 未结 6 584
臣服心动
臣服心动 2020-12-06 17:00

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

6条回答
  •  广开言路
    2020-12-06 17:30

    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();
    }
    

提交回复
热议问题