我有这个使用 NHibernate 的代码
public bool ValidateUser(string username, string password)
{
bool loginResult;
using (var session = SessionFactory.Session)
{
session.BeginTransaction();
var makeQuery = session.Query<User>().SingleOrDefault(x => x.Username == username && x.Password == password);
loginResult = makeQuery != null;
}
return loginResult;
}
我的 SessionFactory 看起来像这样
using NHibernate;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using WebSite.DatabaseModels;
using System;
namespace GameServer.Repository
{
public class SessionFactory
{
private static string connString = System.Configuration.ConfigurationManager.ConnectionStrings["MySQLConnectionString"].ConnectionString;
private static ISessionFactory session;
private static object syncRoot = new Object();
private static ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(MySQLConfiguration
.Standard
.ConnectionString(connString))
.Mappings(m => m.FluentMappings
.AddFromAssemblyOf<UserMap>())
.ExposeConfiguration(UpdateSchema)
.BuildSessionFactory();
}
private static void UpdateSchema(Configuration cfg)
{
new SchemaUpdate(cfg);
}
public static ISession Session
{
get
{
if (session == null)
{
lock (syncRoot)
{
if (session == null)
session = CreateSessionFactory();
}
}
return session.OpenSession();
}
}
^ 我尝试在 Session 属性上放置一个断点,但没有命中,但是在使用 (var session = SessionFactory.Session) 时抛出异常,并且无法真正看到如何在错误报告中修复它