0

The problem is that my MVC app is connecting well to my database but when I query it it doesn't return anything(var model is empty) and I don't know what's the problem.I'm using SharpLite template so this already has automappings implemented and is connecting to my database using NHibernate, I already implemented the User entity in MyProject.Domain. Here is the code in my User Controller:

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

And this is the code from 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;
}
Fateme Mirjalili
  • 762
  • 7
  • 16
Daniel Conde Marin
  • 7,588
  • 4
  • 35
  • 44

2 Answers2

0

You'll want to see the statements sent to the database, along with the results. Try one of these methods:

  • The easiest way I've found is using NHibernate Profiler. It's a pay product.
  • Setup NHibernate to log SQL statements using log4net.
  • Custom output to Trace, Debug, or anywhere else you want using an interceptor

I don't know enough about the problem to pinpoint the error currently.

Community
  • 1
  • 1
Jay Otterbein
  • 948
  • 5
  • 10
0

Verify that your User entity inherits Entity

Sly
  • 15,046
  • 12
  • 60
  • 89