我有一个没有从数据库中获取任何记录的基本方法。在配置中,它可以毫无问题地创建表。它总是返回零记录。我在下面添加了配置文件。我不明白有什么问题。
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();
}
}