Nhibernate create database?

Asked

Viewed 401 times

0

I am a Java developer and work with Hibernate. Now I need to create a desktop application and decided to use C# for this. I’ve been researching ORM frameworks for C# and found Entity Framework and Nhibernate. As my experience is better with Hibernate I decided to adopt Nhibernate but I am searching if it is possible to create the database and tables as it is possible in Hibernate but I have not found anything but table creation.

I wonder if with Nhibernate it is possible to create the database ?

  • 1

    Using Fluent is possible without using it I’ve never seen.

  • @jbueno perfect, thank you. To work with Mysql vc knows how to tell me which libraries are needed ?

  • @Fernandopaiva, the options to configure Nhibernate to create or not the tables in the database are the 3 Schema listed and explained in that reply.

1 answer

1

Good afternoon @Fernandopaiva I do this way with Nhibernate he creates the tables in the bank I will leave link to github with project I used it.

 public class HibernateUtil
    {
        private static ISessionFactory factory;

        public static ISessionFactory Factory
        {
            get
            {
                if (factory == null)
                {

                    factory = Fluently.Configure()
                        .Database(MsSqlConfiguration.MsSql2008
                        .ConnectionString(ConfigurationManager.ConnectionStrings["webapi"].ConnectionString))
                        .Mappings(m => m.FluentMappings.AddFromAssemblyOf<FuncionarioMap>()).
                         ExposeConfiguration(cfg => new SchemaUpdate(cfg).Execute(false, true))
                        .BuildSessionFactory();


                }


                return factory;
            }


        }
    }

https://github.com/EduardoSampaio/ControleFuncionario/blob/master/Projeto.Dal/Util/HibernateUtil.cs

  • I tbm do so, but that way the database is not just created tables. I am looking for a way to create database and also tables.

  • Good with Nhibernate I do not know this option I know that Entity Framework to cases that it even creates database automatically.

  • The Entity Framework creates the database automatically together with the tables ?

  • 1

    It can even create mdf file inside the visual studio , or you can use terminal package manager console you can suggest the database with Enable-Migrations commands and then using update-database -verbose

Browser other questions tagged

You are not signed in. Login or sign up in order to post.