我有一个基本方法,它不会从数据库中获取任何记录。在配置中,它创建表没有问题。它总是返回零记录。我已在下面添加了配置文件。我不明白这是什么问题。
public List<Note> GetAll()
{
var session = NHibernateHelper.OpenSession();
var note = session.CreateCriteria<Note>().List<Note>();
return note.ToList();
}
帮助者:
public class NHibernateHelper
{
private static ISessionFactory _sessionFactory;
private static ISessionFactory SessionFactory
{
get
{
if (_sessionFactory == null)
{
InitializeSessionFactory();
}
return _sessionFactory;
}
}
private static void InitializeSessionFactory()
{
_sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(
@"Server={server};Database=ToDo;
User ID=lorem;Password=lorem;
Trusted_Connection=False;Encrypt=True;Connection Timeout=30;")
.ShowSql()
)
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Note>())
.ExposeConfiguration(cfg => new SchemaExport(cfg)
.Create(true, true))
.BuildSessionFactory();
}
public static ISession OpenSession()
{
return SessionFactory.OpenSession();
}
}
答案 0 :(得分:0)
试试这个: