0

默认情况下,从 Sharp Architecture 的 templify 包生成的解决方案使用项目NHibernate.config中的文件配置 NHibernate {SolutionName}.Web。我想用我自己的流畅配置替换它,并且仍然让 Sharp Architecture 的其余部分正常工作。

任何帮助都感激不尽。:)

解决方案:这是我如何让它工作的:

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);
4

2 回答 2

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;
    }
于 2013-04-30T10:47:25.283 回答
0

iirc 用于配置 nhibernate 的 NhibernateSession 类有一堆重载,其中一个使您能够通过代码对其进行配置。

于 2011-04-18T18:13:39.527 回答