Creating connection with MySQL with FluentNHibernate?

1

I'm trying to create a connection to MySQL using NHibernate and FluentNHibernate. I added by% n of% but when I try to create the connection MySql.Data is not found in the context.

I'm trying like this.

private static ISessionFactory getConnection(){
    return Fluently.Configure().
            Database(MySQLConfiguration.Standard.ConnectionString(
            x=>x.Server("localhost").
               Username("root").
               Password("").
               Database("usuarios_db")
            )).
            Mappings(m => m.FluentMappings.AddFromAssemblyOf<UsuarioMap>()).
            ExposeConfiguration(cfg => new SchemaUpdate(cfg).Execute(false, true)).
            BuildSessionFactory();
}
    
asked by anonymous 27.02.2016 / 02:28

1 answer

1

Resolved.

As I did not know what using were needed to make the connection, I got a bit of a catch because my Visual Studio 2012 is not automatically doing using , this is a problem that I still can not solve if someone knows how to solve it and can help I appreciate it.

Here's how it went.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NHibernate;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using ControleUsuarios.Map;
using NHibernate.Tool.hbm2ddl;


namespace ControleUsuarios.BD {

    public class BDConnect {

        private static ISessionFactory session;
        private static const String HOST = "localhost";
        private static const String USER = "root";
        private static const String PASSWORD = "";
        private static const String DB = "usuario_db";        

        /** create a connection with database */
        private static ISessionFactory createConnection() {

            if (session != null)
                return session;

            //database configs
            FluentConfiguration _config = Fluently.Configure().Database(MySQLConfiguration.Standard.ConnectionString(
                                                                       x => x.Server(HOST).
                                                                          Username(USER).
                                                                          Password(PASSWORD).
                                                                          Database(DB)
                                                                        ))
                                                                        .Mappings(m => m.FluentMappings.AddFromAssemblyOf<UsuarioMap>())
                                                                        .ExposeConfiguration(cfg => new SchemaUpdate(cfg).Execute(false, true));

            session = _config.BuildSessionFactory();
            return session;
        }


        /** open a session to make transactions */
        public static ISession openSession() {
            return createConnection().OpenSession();
        }



    }
}
    
27.02.2016 / 05:52