0

デフォルトでは、Sharp Architectureのtemplifyパッケージから生成されたソリューションNHibernate.configは、プロジェクト内のファイルを使用してNHibernateを構成します{SolutionName}.Web。私はそれを私自身の流暢な構成に置き換え、それでも残りのシャープアーキテクチャを正しく機能させたいと思います。

どんな助けでも大歓迎です。:)

解決策:これが私がそれを機能させる方法です:

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

iirc nhibernateの構成に使用されるNhibernateSessionクラスには、コードを介して構成する機能を提供するオーバーロードの束があります。

于 2011-04-18T18:13:39.527 に答える
0

非常に古い投稿。他の誰かが興味を持った場合に備えて、ここに残しておきます。SharpArch 1.9.6.0では、NHibernateSession.csに2つのメソッドを追加できます。これにより、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 に答える