Home > database >  I have a problem creating the records in the database. I don't know what it could be
I have a problem creating the records in the database. I don't know what it could be

Time:10-29

I have a problem creating the records in the database.

I don't know what it could be.

This happens when I restart the application, and the biggest problem is that the application doesn't return an error.

I'm using AspnetCore and NHibernate.

I think that would be the problem here, but I'm posting the project link.

public void ConfigureServices(IServiceCollection services)
{
  //
  var _sessionFactory = Fluently.Configure()
        .Database(PostgreSQLConfiguration.Standard.ConnectionString(Configuration.GetConnectionString("DefaultConnection")))
        .Mappings(x => x.FluentMappings.AddFromAssembly(GetType().Assembly))
        .ExposeConfiguration(cfg =>
                  {
                    var schemaExport = new SchemaExport(cfg);
                    schemaExport.Drop(false, false);
                    schemaExport.Create(true, true);
                  })
        .BuildSessionFactory();

     services.AddScoped(f =>
    {
      return _sessionFactory.OpenSession();
    });

 services.AddControllersWithViews();
}

Project on GitHub - https://github.com/MatheusHenrique421/Hibernate_/tree/master

CodePudding user response:

The following line of code will drop and create the database:

schemaExport.Create(true, true);

Every time you start the application that line of code executes as part of the application bootstrapping.

  • Related