我最近从GitHub(最新版本)获得了Fluent NHibernate,但是当我在调试模式下实例化FluentConfiguration实例时,我被提示输入NHibernate的Configuration.cs文件的位置。我查看了NHibernate的源代码,但一直无法找到它。我使用Visual Studio从源代码构建,并且想知道我是否有可能犯了这样的错误。有人能指出我正确的方向,如何解决这个问题?我的版本是3.2。
更新
我的调试器正式搞砸了 - 我的ISession变量在堆栈跟踪上超时,说明“功能评估被禁用,因为之前的功能评估超时。你必须继续执行以重新启用函数eval。”
我会发布 config 文件,在这里:
<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>
这是调用我的核心库的调用者,它作为app.config文件:
<?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>
最后,Fluent Config
return Fluently.Configure()
.Database(
MySQLConfiguration.Standard.ConnectionString(_connectionString)
)
.Mappings(
m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly())
)
.BuildSessionFactory();
答案 0 :(得分:1)
由于某些原因,调试器似乎无法确切地指出出现问题的确切位置。但根据我的经验,当VS要求您使用Configuration.cs或FluentConfiguration.cs时,这意味着当您调用BuildSessionFactory()时会出现问题。
我会在那次通话之前设置一个断点,看看你是否在它之前但没有进一步。由于您的标签表明您正在使用Fluent NHibernate,因此逐步使用流畅的api也无法正常工作。您可能希望通过重复分配FluentConfiguration来进行分块,以便能够逐步完成它。
也许您没有正确公开配置。或者您可能正在使用InMemory SQLite数据库。在后一种情况下,您必须将配置存储在变量中,并在打开会话后构建模式。 (每个InMemory会话都有自己的内存数据库。)
最后,问题可能是为您的不同项目加载的不同版本。我建议使用NuGet,并在解决方案级别而不是项目级别管理包,以避免类似的问题。
最后,您可能正在使用错误的SQLite程序集。你在运行32位还是64位?
所以,那是在黑暗中拍摄的几张照片。希望他们会帮助你找到你的bug。