0

默认情况下,Sharp Architecture的templify软件包生成的解决方案使用{SolutionName}.Web项目中的NHibernate.config文件配置NHibernate。我想用我自己的流畅配置替换它,并且仍然能够正确地运行夏普体系结构的其余部分。使用Fluent配置替换Sharp Architecture的NHibernate.config

任何帮助将不胜感激。 :)

解决方案:这就是我得到了它的工作:

IPersistenceConfigurer configurer = OracleClientConfiguration.Oracle10 
    .AdoNetBatchSize(500) 
    .ShowSql() 
    .ConnectionString(c => c.FromConnectionStringWithKey("NHibernate.Localhost")) 
    .DefaultSchema("MySchema") 
    .ProxyFactoryFactory("NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle") 
    .UseReflectionOptimizer(); 

NHibernateSession.Init(
    webSessionStorage, 
    new string[] { Server.MapPath("~/bin/MyProject.Data.dll") }, 
    new AutoPersistenceModelGenerator().Generate(), 
    null, 
    null, 
    null, 
    configurer); 

回答

0

IIRC用来配置NHibernate的该NhibernateSession类有一堆重载其中一人给你配置它的能力通过代码。

+0

我看不到我要发送Fluent配置变量的位置,没有。 – rebelliard 2011-04-18 20:27:37

+0

hi -sorry你默认是正确的,从我看到你只能通过配置属性的字典,但最终在内部该类使用流利配置返回会话工厂。你可能需要修改这个类来让它接受流畅的配置。 – maciek 2011-04-19 00:48:16

+0

谢谢,我得到它与一堆完全不自然的nulls一起工作。 :d – rebelliard 2011-04-19 13:15:04

0

很旧的帖子。如果其他人感兴趣,我会把它留在这里。在SharpArch 1.9.6.0上,您可以将两种方法添加到NHibernateSession.cs中。这将允许您传入FluentConfiguration对象。

public static FluentConfiguration Init(ISessionStorage storage, FluentConfiguration fluentConfiguration) 
    { 
     InitStorage(storage); 
     try 
     { 
      return AddConfiguration(DefaultFactoryKey, fluentConfiguration); 
     } 
     catch 
     { 
      // If this NHibernate config throws an exception, null the Storage reference so 
      // the config can be corrected without having to restart the web application. 
      Storage = null; 
      throw; 
     } 
    } 

    private static FluentConfiguration AddConfiguration(string defaultFactoryKey, FluentConfiguration fluentConfiguration) 
    { 
     var sessionFactory = fluentConfiguration.BuildSessionFactory(); 
     Check.Require(!sessionFactories.ContainsKey(defaultFactoryKey), 
      "A session factory has already been configured with the key of " + defaultFactoryKey); 

     sessionFactories.Add(defaultFactoryKey, sessionFactory); 

     return fluentConfiguration; 
    }