公开会议:
private static ISession OpenSession(string dbKey)
{
try
{
var interceptor = new SetSystemPropertiesInterceptor(
() => DependencyResolver.Current.GetService<IAuthenticationService>()
);
ISession session;
session = NHibernateSessionHelper.GetFactory(dbKey).OpenSession();
if (session == null)
throw new InvalidOperationException(string.Format("Call to factory.OpenSession('{0}') returned null.", dbKey));
session.FlushMode = FlushMode.Never;
session.BeginTransaction();
interceptor.SetSession(session);
return session;
}
catch (Exception ex)
{
throw new Exception(string.Format("Error on database with key '{0}'", dbKey), ex);
}
}
Factory Informix:
public static ISessionFactory GetFactory(string databaseKey)
{
if (!factories.ContainsKey(databaseKey))
{
lock (syncObject)
{
if (!factories.ContainsKey(databaseKey))
{
ISessionFactory factory = Fluently.Configure()
.Database(
IfxSQLIConfiguration
.Informix1000
.Provider<NHibernate.Connection.DriverConnectionProvider>()
.Driver<NHibernate.Driver.IfxDriver>()
.Dialect<NHibernate.Dialect.InformixDialect>()
.ConnectionString(c => c.FromConnectionStringWithKey(databaseKey))
.ShowSql())
.Mappings(x => x.FluentMappings.AddFromAssemblyOf<TvLoginMapping>()
.Conventions.AddFromAssemblyOf<CustomTypeConvention>()
)
.BuildSessionFactory();
factories.Add(databaseKey, factory);
}
}
}
return factories[databaseKey];
}
映射示例:
public class TvLoginMapping : ClassMap<TvLogin>
{
public TvLoginMapping()
{
this.Table("tvlogin");
this.Id(X => X.u4976_38748);
this.Map(X => X.cdlogin);
this.Map(X => X.nrgrafico);
}
}
错误:创建SessionFactory时使用了无效或不完整的配置。检查PotentialReasons集合,以及InnerException以获取更多详细信息。
我如何调试?