Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using FluentNHibernate.Cfg;
- using FluentNHibernate.Cfg.Db;
- using NHibernate;
- using NHibernate.Cfg;
- using NHibernate.Tool.hbm2ddl;
- namespace RockStars6
- {
- public static class Database
- {
- /// <summary>
- /// Gets a reference to the logger.
- /// </summary>
- //private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
- public static void init()
- {
- // Need nHibernate init code here.
- using (ISession database = OpenSession())
- {
- }
- }
- private static ISessionFactory _sessionFactory;
- public static ISessionFactory Factory
- {
- get { return _sessionFactory ?? (_sessionFactory = CreateSessionFactory()); }
- }
- public static ISession OpenSession()
- {
- return Factory.OpenSession();
- }
- private static ISessionFactory CreateSessionFactory()
- {
- return Fluently.Configure()
- .Database(
- MySQLConfiguration.Standard
- .ConnectionString("Server=127.0.0.1;Port=3306;Database=rockstars6dev;User ID=root;")
- )
- .Mappings(m =>
- m.FluentMappings.AddFromAssemblyOf<GameMode>())
- .ExposeConfiguration(TreatConfiguration)
- .BuildSessionFactory();
- }
- private static void TreatConfiguration(Configuration configuration)
- {
- var update = new SchemaUpdate(configuration);
- update.Execute(false, true);
- //configuration.SetInterceptor(new SqlStatementInterceptor());
- // Expirimental: Create DB.
- //new SchemaExport(configuration).Create(true, true);
- var validateDatabase = new SchemaExport(configuration);
- validateDatabase.SetOutputFile("GeneratedSQL.sql");
- //validateDatabase.Execute(false, true, false);
- // WARNING: Uncommenting the above line will WIPE THE ENTIRE DB!!
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement