0

在中等信任环境中使用 Unity + Fluent NHibernate + NHibernate 3.3.1.4

var session = sessionFactory.OpenSession();

返回此错误:

Attempt by method 'NHibernate.AdoNet.SqlClientSqlCommandSet..ctor()' to access method 'System.Data.SqlClient.SqlCommandSet..ctor()' failed.

   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at NHibernate.AdoNet.SqlClientSqlCommandSet..ctor()
   at NHibernate.AdoNet.SqlClientBatchingBatcher.CreateConfiguredBatch()
   at NHibernate.AdoNet.SqlClientBatchingBatcher..ctor(ConnectionManager connectionManager, IInterceptor interceptor)
   at NHibernate.AdoNet.SqlClientBatchingBatcherFactory.CreateBatcher(ConnectionManager connectionManager, IInterceptor interceptor)
   at NHibernate.AdoNet.ConnectionManager..ctor(ISessionImplementor session, IDbConnection suppliedConnection, ConnectionReleaseMode connectionReleaseMode, IInterceptor interceptor)
   at NHibernate.Impl.SessionImpl..ctor(IDbConnection connection, SessionFactoryImpl factory, Boolean autoclose, Int64 timestamp, IInterceptor interceptor, EntityMode entityMode, Boolean flushBeforeCompletionEnabled, Boolean autoCloseSessionEnabled, ConnectionReleaseMode connectionReleaseMode)
   at NHibernate.Impl.SessionFactoryImpl.OpenSession(IDbConnection connection, Boolean autoClose, Int64 timestamp, IInterceptor sessionLocalInterceptor)
   at NHibernate.Impl.SessionFactoryImpl.OpenSession(IInterceptor sessionLocalInterceptor)
   at NHibernate.Impl.SessionFactoryImpl.OpenSession()
   at BsCms.Bootstrapper.<>c__DisplayClass5.<BuildUnityContainer>b__2(IUnityContainer c)
   at Microsoft.Practices.Unity.InjectionFactory.<>c__DisplayClass2.<.ctor>b__0(IUnityContainer c, Type t, String s)
   at Microsoft.Practices.ObjectBuilder2.FactoryDelegateBuildPlanPolicy.BuildUp(IBuilderContext context)
   at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)
   at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)

有人能帮我吗?

4

1 回答 1

0

这是一个很容易解决的问题。您必须禁用批处理。您可以通过将属性设置adonet.batch_size0

在/的您hibernate.cfg.xml或休眠配置部分中:App.configWeb.config

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <reflection-optimizer use="false"/>
  <session-factory>
    <!-- other properties -->
    <property name="adonet.batch_size">0</property>
  </session-factory>
</hibernate-configuration>

或者通过 FluentNHibernate:

var db = MsSqlConfiguration.MsSql2008
    // other configurations
    .AdoNetBatchSize(0); 

return Fluently.Configure()
    // other configurations
    .Database(db)
    .BuildConfiguration();
于 2012-09-23T10:54:45.813 回答