使用SharpLite从PostgreSQL数据库中检索数据。

问题描述 投票:0回答:2

问题是,我的MVC应用程序与数据库连接良好,但当我查询它时,它没有返回任何东西(var modelempty),我不知道问题出在哪里。SharpLite 模板,所以这已经实现了自动应用,并且正在使用 NHibernate,我已经实现了 User 中的实体 MyProject.Domain.以下是我的代码 User Controller:

private readonly IRepository<User> _repository; 
public UserController(IRepository<User> repository)
{
    _repository = repository;
}
public ActionResult Index()
{
    var model = _repository.GetAll();
    return View(model);
}

这是我的代码 NHibernate initializer:

public static Configuration Initialize() 
{
    var configuration = new Configuration();

    configuration
         .Proxy(p => p.ProxyFactoryFactory<DefaultProxyFactoryFactory>())
          .DataBaseIntegration(db => {
             db.ConnectionStringName = "MyProjectConnectionString";
             db.Dialect<PostgreSQL82Dialect>();
          })
          .AddAssembly(typeof(ActionConfirmation<>).Assembly)
          .CurrentSessionContext<LazySessionContext>();

    var mapper = new ConventionModelMapper();
    mapper.WithConventions(configuration);

    return configuration;
}
asp.net-mvc asp.net-mvc-3 model-view-controller nhibernate nhibernate-mapping
2个回答
0
投票

你会想看看发送到数据库的语句,以及结果,试试这些方法之一。

  • 我发现最简单的方法是使用... ... NHibernate剖析器. 这是一个付费产品。
  • 设置NHibernate来记录SQL语句,使用的是 log4net.
  • 自定义输出到Trace、Debug或其他任何你想要的地方。拦截器

我对这个问题还不够了解,目前还不能确定错误。


0
投票

验证您的 User 实体继承 Entity

© www.soinside.com 2019 - 2024. All rights reserved.