【问题标题】:Retrieving data from PostgreSQL database using SharpLite使用 SharpLite 从 PostgreSQL 数据库中检索数据
【发布时间】:2012-03-23 03:24:56
【问题描述】:

问题是我的 MVC 应用程序可以很好地连接到我的数据库,但是当我查询它时它没有返回任何内容(var modelempty)而且我不知道是什么问题。我正在使用SharpLite 模板,所以它已经实现了自动映射,并使用NHibernate 连接到我的数据库,我已经在MyProject.Domain 中实现了User 实体。 这是我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


    【解决方案1】:

    您会希望查看发送到数据库的语句以及结果。 尝试以下方法之一:

    • 我发现最简单的方法是使用NHibernate Profiler。这是一种付费产品。
    • 设置 NHibernate 以使用 log4net 记录 SQL 语句。
    • 自定义输出到跟踪、调试或使用an interceptor 的任何其他位置

    我对问题的了解还不够,无法确定当前的错误。

    【讨论】:

      【解决方案2】:

      验证您的User 实体是否继承Entity

      【讨论】:

        猜你喜欢
        • 2010-09-25
        • 2015-07-07
        • 1970-01-01
        • 2016-01-29
        • 1970-01-01
        • 1970-01-01
        • 2019-11-19
        相关资源
        最近更新 更多