简体   繁体   中英

NHibernate Configuration.cs File Missing

I recently obtained Fluent NHibernate from GitHub (latest version), though when I instantiate an instance of FluentConfiguration while in debug mode, I get prompted for the location of NHibernate's Configuration.cs file. I've looked in NHibernate's source, and haven't been able to find it. I used Visual Studio to build from source, and am wondering if there's a chance that I may have made a mistake for doing that. Could someone point me in the right direction as how to solve this? My version is 3.2.

Update

My debugger is officially screwed - my ISession variable is timing out on the stacktrace, stating that the "function evaluation is disabled because a previous function evaluation timed out. You must continue execution to re-enable function eval."

I'll post my config file, here:

<configSections>
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
  </configSections>

  <connectionStrings>
    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
    <add name="LocalMySQLConnection" connectionString="Data Source=localhost;uid=root;password=a2ey7x103;Database=cms_main"
    providerName="MySQL.Data.MySqlClient"/>
  </connectionStrings>

  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <bytecode-provider type="lcg" />
    <reflection-optimizer use="true" />
    <session-factory name="Dope">
      <!--<property name="query.factory_class">NHibernate.Hql.Classic.ClassicQueryTranslatorFactory, NHibernate</property>
-->
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <property name="cache.provider_class">NHibernate.Cache.HashtableCacheProvider, NHibernate</property>
      <property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
      <property name="cache.use_query_cache">true</property>
      <property name="query.startup_check">false</property>
      <property name="use_proxy_validator">true</property>
      <!-- 
        The valid strings for Isolation can be found in the documentation for the System.Data.IsolationLevel
        Enumeration documentation.
        Use the member names - not the values.
      -->
      <property name="adonet.batch_size">16</property>
      <property name="generate_statistics">true</property>
      <property name="connection.isolation">ReadCommitted</property>
      <property name="hbm2ddl.keywords">none</property>
      <property name="format_sql">true</property>
      <property name="proxyfactory.factory_class">
          NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle
      </property>
      <!-- This is the System.Data.dll provider for MSSQL Server -->

      <property name="dialect">
          <!--NHibernate.Dialect.MsSql2008Dialect-->
          NHibernate.Dialect.MySQLDialect
      </property>
      <property name="connection.connection_string">
          <!--Server=.\SQLExpress;initial catalog=nhibernate;Integrated Security=SSPI-->
          <!--data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true-->
          Server=localhost;User ID=root;Password=a2ey7x103;Database=cms_main;  
      </property>
      <property name="show_sql">true</property>
      <property name="command_timeout">444</property>
      <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
      <property name="adonet.wrap_result_sets">false</property>
    </session-factory>
  </hibernate-configuration>
  <!-- This section contains the log4net configuration settings -->
  <log4net debug="false">
    <!-- Define some output appenders -->
    <appender name="trace" type="log4net.Appender.TraceAppender, log4net">
      <layout type="log4net.Layout.PatternLayout,log4net">
        <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" />
      </layout>
    </appender>
    <appender name="console" type="log4net.Appender.ConsoleAppender, log4net">
      <layout type="log4net.Layout.PatternLayout,log4net">
        <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" />
      </layout>
    </appender>
    <appender name="rollingFile" type="log4net.Appender.RollingFileAppender,log4net">
      <param name="File" value="log.txt" />
      <param name="AppendToFile" value="false" />
      <param name="RollingStyle" value="Date" />
      <param name="DatePattern" value="yyyy.MM.dd" />
      <param name="StaticLogFileName" value="true" />
      <layout type="log4net.Layout.PatternLayout,log4net">
        <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
      </layout>
    </appender>
    <!-- Setup the root category, add the appenders and set the default priority -->
    <root>
      <priority value="WARN" />
      <appender-ref ref="console" />
    </root>
    <logger name="NHibernate.Hql.Ast.ANTLR">
      <priority value="OFF" />
    </logger>
    <logger name="NHibernate.SQL">
      <level value="OFF" />
    </logger>
    <logger name="NHibernate.AdoNet.AbstractBatcher">
      <level value="OFF" />
    </logger>
    <logger name="NHibernate.Tool.hbm2ddl.SchemaExport">
      <level value="ERROR" />
    </logger>
  </log4net>

That's for the caller which calls to my core library, which as an app.config file of:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
    </configSections>

    <connectionStrings>
        <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
        <add name="LocalMySQLConnection" connectionString="Data Source=localhost;uid=root;password=a2ey7x103;Database=cms_main"
        providerName="MySQL.Data.MySqlClient"/>
    </connectionStrings>

    <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
        <bytecode-provider type="lcg" />
        <reflection-optimizer use="true" />
        <session-factory name="Dope">
            <!--<property name="query.factory_class">NHibernate.Hql.Classic.ClassicQueryTranslatorFactory, NHibernate</property>
-->
            <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
            <property name="cache.provider_class">NHibernate.Cache.HashtableCacheProvider, NHibernate</property>
            <property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
            <property name="cache.use_query_cache">true</property>
            <property name="query.startup_check">false</property>
            <property name="use_proxy_validator">true</property>
            <!-- 
        The valid strings for Isolation can be found in the documentation for the System.Data.IsolationLevel
        Enumeration documentation.
        Use the member names - not the values.
      -->
            <property name="adonet.batch_size">16</property>
            <property name="generate_statistics">true</property>
            <property name="connection.isolation">ReadCommitted</property>
            <property name="hbm2ddl.keywords">none</property>
            <property name="format_sql">true</property>
            <property name="proxyfactory.factory_class">
                NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle
            </property>
            <!-- This is the System.Data.dll provider for MSSQL Server -->

            <property name="dialect">
                <!--NHibernate.Dialect.MsSql2008Dialect-->
                NHibernate.Dialect.MySQLDialect
            </property>
            <property name="connection.connection_string">
                <!--Server=.\SQLExpress;initial catalog=nhibernate;Integrated Security=SSPI-->
                <!--data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true-->
                Server=localhost;User ID=root;Password=a2ey7x103;Database=cms_main;
            </property>
            <property name="show_sql">true</property>
            <property name="command_timeout">444</property>
            <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
            <property name="adonet.wrap_result_sets">false</property>
        </session-factory>
    </hibernate-configuration>
    <!-- This section contains the log4net configuration settings -->
    <log4net debug="false">
        <!-- Define some output appenders -->
        <appender name="trace" type="log4net.Appender.TraceAppender, log4net">
            <layout type="log4net.Layout.PatternLayout,log4net">
                <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" />
            </layout>
        </appender>
        <appender name="console" type="log4net.Appender.ConsoleAppender, log4net">
            <layout type="log4net.Layout.PatternLayout,log4net">
                <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" />
            </layout>
        </appender>
        <appender name="rollingFile" type="log4net.Appender.RollingFileAppender,log4net">
            <param name="File" value="log.txt" />
            <param name="AppendToFile" value="false" />
            <param name="RollingStyle" value="Date" />
            <param name="DatePattern" value="yyyy.MM.dd" />
            <param name="StaticLogFileName" value="true" />
            <layout type="log4net.Layout.PatternLayout,log4net">
                <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
            </layout>
        </appender>
        <!-- Setup the root category, add the appenders and set the default priority -->
        <root>
            <priority value="WARN" />
            <appender-ref ref="console" />
        </root>
        <logger name="NHibernate.Hql.Ast.ANTLR">
            <priority value="OFF" />
        </logger>
        <logger name="NHibernate.SQL">
            <level value="OFF" />
        </logger>
        <logger name="NHibernate.AdoNet.AbstractBatcher">
            <level value="OFF" />
        </logger>
        <logger name="NHibernate.Tool.hbm2ddl.SchemaExport">
            <level value="ERROR" />
        </logger>
    </log4net>
</configuration>

And finally, the Fluent Config

return Fluently.Configure()
                    .Database(
                       MySQLConfiguration.Standard.ConnectionString(_connectionString)
                    )
                    .Mappings(
                        m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly())
                    )
                    .BuildSessionFactory();

For some reason the debugger doesn't seem to be able to pinpoint exactly where something goes wrong with this. But in my experience, when VS asks you for either Configuration.cs or FluentConfiguration.cs, that means something goes wrong when you call BuildSessionFactory().

I'd setting a breakpoint before that call, and see if you get to just before it but no further. As your tag is indicating you're using Fluent NHibernate, stepping through a fluent api doesn't work as well. You might want to chunk it up by doing repeated assignments of the FluentConfiguration to be able to step through it.

Perhaps you're not exposing the configuration correctly. Or perhaps you're using an InMemory SQLite database. In the latter case you will have to store the configuration in a variable and build the schema after you open the session. (Each InMemory session gets its own memory database.)

Finally the problem could be different versions loaded for different projects of yours. I recommend using NuGet, and managing your packages on the solution level as opposed to the project level, to avoid problems like that.

Finally, you might be using the wrong SQLite assembly. Are you running 32 or 64 bit?

So, that was a few shots in the dark. Hopefully they'll help you hunt down your bug though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM