本文整理汇总了C#中NHibernate.Tool.hbm2ddl.SchemaExport.Create方法的典型用法代码示例。如果您正苦于以下问题:C# SchemaExport.Create方法的具体用法?C# SchemaExport.Create怎么用?C# SchemaExport.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NHibernate.Tool.hbm2ddl.SchemaExport
的用法示例。
在下文中一共展示了SchemaExport.Create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DatabaseRegistry
public DatabaseRegistry()
{
var nHibernateConfiguration = new EmployeeApplicationNHibernateConfiguration();
//string connectionString = ConfigurationManager.ConnectionStrings["EmployeeApplicationContext"].ConnectionString;
ISessionFactory sessionFactory = Fluently
.Configure()
.Database(SQLiteConfiguration.Standard.UsingFile(@"sqlite.db"))
//.Database(MsSqlConfiguration.MsSql2008.ConnectionString(connectionString))
.Mappings(m =>
m.AutoMappings
.Add(AutoMap.AssemblyOf<Employee>(nHibernateConfiguration))
)
.ExposeConfiguration(cfg =>
{
var schemaExport = new SchemaExport(cfg);
schemaExport.Drop(true, true);
schemaExport.Create(true, true);
})
.BuildSessionFactory();
For<ISessionFactory>().Singleton().Use(sessionFactory);
For<ISession>().HybridHttpOrThreadLocalScoped().Use(ctx => ctx.GetInstance<ISessionFactory>().OpenSession());
//TODO: Handle Tansactions For Application
//For<IUnitOfWork>().CacheBy(new HybridLifecycle()).Use<UnitOfWork>();
}
示例2: Create
public string Create()
{
var schemaExport = new SchemaExport(configuration);
databaseProvider.CreateIfNotExists();
var stringBuilder = new StringBuilder();
schemaExport.Create(x => stringBuilder.Append(x), false);
var statement = stringBuilder.ToString();
statement = string.IsNullOrWhiteSpace(statement) ? null : statement;
if (!databaseProvider.Exists())
{
databaseProvider.Create();
schemaExport.Execute(false, true, false);
}
else
{
try
{
new SchemaValidator(configuration).Validate();
}
catch
{
schemaExport.Execute(false, true, false);
}
}
return statement;
}
示例3: CreateDataBase
//�������ݿ�
public static void CreateDataBase(string AssemblyName)
{
cfg = new Configuration();
cfg.AddAssembly(AssemblyName);
SchemaExport sch = new SchemaExport(cfg);
sch.Create(true, true);
}
示例4: BuildSchema
private static void BuildSchema()
{
NHibernate.Cfg.Configuration cfg = NHibernateConfigurator.Configuration;
var schemaExport = new SchemaExport(cfg);
schemaExport.Create(false, true);
// A new session is created implicitly to run the create scripts. But this new session is not the context session
}
示例5: HelloWorldStructureMapRegistry
public HelloWorldStructureMapRegistry()
{
IncludeRegistry<ProAceCoreRegistry>();
var sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("HelloWorld")).ShowSql())
.Mappings(m =>
{
m.FluentMappings.AddFromAssemblyOf<MapMarker>();
m.FluentMappings.Conventions.AddFromAssemblyOf<CollectionAccessConvention>();
})
.ExposeConfiguration(cfg =>
{
var schemaExport = new SchemaExport(cfg);
schemaExport.Drop(true, true);
schemaExport.Create(true, true);
For<NHibernate.Cfg.Configuration>().Use(cfg);
})
.BuildSessionFactory();
For<ISessionFactory>()
.Singleton()
.Use(sessionFactory);
For<ISession>()
.Use(ctx => ctx.GetInstance<ISessionFactory>().OpenSession());
For<IUserRepository>().Use<UserRepository>();
}
示例6: btnGenerateDBScript_Click
private void btnGenerateDBScript_Click(object sender, RoutedEventArgs e)
{
Assembly assembly = Assembly.LoadFrom(txtFileName.Text);
IPersistenceConfigurer databaseConfig = null;
string fileName = "Domain Database Script - {0}.sql";
if (rdbSqlServer.IsChecked != null)
if (rdbSqlServer.IsChecked.Value)
{
databaseConfig = MsSqlConfiguration.MsSql2005;
fileName = string.Format(fileName, "Sql Server 2005");
}
else if (rdbOracle.IsChecked != null)
if (rdbOracle.IsChecked.Value)
{
databaseConfig = OracleDataClientConfiguration.Oracle9;
fileName = string.Format(fileName, "Oracle 9g");
}
Fluently.Configure()
.Mappings(m => m.FluentMappings.AddFromAssembly(assembly))
.Database(databaseConfig)//.ConnectionString("Data Source=.\\SQLEXPRESS;Initial Catalog=master;Integrated Security=True"))
.ExposeConfiguration(config =>
{
SchemaExport se = new SchemaExport(config);
se.SetOutputFile(fileName);
se.Create(false, false);
MessageBox.Show(string.Format("Script successful created! See the '{0}' file.", fileName));
}).BuildConfiguration();
}
示例7: BuildSchema
private void BuildSchema(Configuration config)
{
SchemaExport schema = new SchemaExport(config);
schema.Drop(this._criaScript, this._exportaScriptBD);
schema.Create(this._criaScript, this._exportaScriptBD);
config.SetInterceptor(new SqlStatementInterceptor());
}
示例8: NHibernateManager
/// <summary>
/// Initiate NHibernate Manager
/// </summary>
/// <param name="connect">NHibernate dialect, driver and connection string separated by ';'</param>
/// <param name="store">Name of the store</param>
public NHibernateManager(string connect, string store)
{
try
{
ParseConnectionString(connect);
//To create sql file uncomment code below and write the name of the file
SchemaExport exp = new SchemaExport(configuration);
exp.SetOutputFile("db_creation.sql");
exp.Create(false, true);
sessionFactory = configuration.BuildSessionFactory();
}
catch (MappingException mapE)
{
if (mapE.InnerException != null)
Console.WriteLine("[NHIBERNATE]: Mapping not valid: {0}, {1}, {2}", mapE.Message, mapE.StackTrace, mapE.InnerException.ToString());
else
m_log.ErrorFormat("[NHIBERNATE]: Mapping not valid: {0}, {1}", mapE.Message, mapE.StackTrace);
}
catch (HibernateException hibE)
{
Console.WriteLine("[NHIBERNATE]: HibernateException: {0}, {1}", hibE.Message, hibE.StackTrace);
}
catch (TypeInitializationException tiE)
{
Console.WriteLine("[NHIBERNATE]: TypeInitializationException: {0}, {1}", tiE.Message, tiE.StackTrace);
}
}
示例9: Application_Start
protected void Application_Start()
{
new Configurator().StartServer<Configurator>();
var cfg = Simply.Do.GetNHibernateConfig();
var check = new SchemaValidator(cfg);
try
{
check.Validate();
}
catch
{
var exp = new SchemaExport(Simply.Do.GetNHibernateConfig());
exp.Drop(true, true);
exp.Create(true, true);
using (Simply.Do.EnterContext())
{
UserSample.Init();
GroupSample.Init();
}
}
RegisterRoutes(RouteTable.Routes);
}
示例10: can_create_schema
public void can_create_schema()
{
Configuration cfg = new NHibernate.Cfg.Configuration();
SchemaExport exporter = new SchemaExport(cfg.Configure());
exporter.Create(true, true);
exporter.Execute(false, true, false, true);
}
示例11: CreateDb
public static void CreateDb()
{
var config = new Configuration().Configure(GetPath() + "\\nhibernate.cfg.xml");
var schemaExport = new SchemaExport(config);
schemaExport.Drop(true, false);
schemaExport.Create(true, true);
}
示例12: First_we_need_a_schema_to_test
public void First_we_need_a_schema_to_test()
{
var schemaExport = new SchemaExport(_cfg);
schemaExport.Drop(true, true);
schemaExport.Create(true, true);
try
{
using (IUnitOfWork work = UnitOfWork.Start())
using (ITransaction transaction = work.BeginTransaction(IsolationLevel.Serializable))
{
using (var repository = new NHibernateRepository())
{
repository.Save(new TestSaga(_sagaId) { Name = "Joe" });
repository.Save(new TestSaga(CombGuid.Generate()) { Name = "Chris" });
work.Flush();
transaction.Commit();
}
}
}
finally
{
UnitOfWork.Finish();
}
}
示例13: CriarSchema
public void CriarSchema()
{
// Apenas no Init da Aplicação
var config = new Configuration();
config.DataBaseIntegration(c =>
{
c.Dialect<MsSql2012Dialect>();
c.ConnectionStringName = "ExemploNH";
c.LogFormattedSql = true;
c.LogSqlInConsole = true;
c.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
});
var modelMapper = new ModelMapper();
modelMapper.AddMappings(typeof (ProdutoMap).Assembly.GetExportedTypes());
config.AddDeserializedMapping(modelMapper.CompileMappingForAllExplicitlyAddedEntities(), "Domain");
ISessionFactory sessionFactory = config.BuildSessionFactory();
// NOTE: Estudar framework FluentMigration
var schemaExport = new SchemaExport(config);
schemaExport.Create(true, true);
}
示例14: BuildTestSessionFactory
private static ISessionFactory BuildTestSessionFactory() {
var testDatabaseConnectionString = "LocalDB";
var config = DatabaseConfiguration.Configure(testDatabaseConnectionString);
/*
* Need to comment these out when not needed because session factory can only be created once.
* Database schemas need to be created BEFORE NHibernate schema export.
* This needs to be run only once.
*/
/*
var fac = DatabaseConfiguration.BuildSessionFactory(config);
CreateSchemas(fac);*/
// Drop old database if any, create new schema
config.ExposeConfiguration(cfg => {
var export = new SchemaExport(cfg);
//export.SetOutputFile(@"C:\Temp\vdb.sql");
export.Drop(false, true);
export.Create(false, true);
});
var fac = DatabaseConfiguration.BuildSessionFactory(config);
FinishDatabaseConfig(fac);
return fac;
}
示例15: BuildDatabase
private static void BuildDatabase(ISessionBuilder builder)
{
Configuration config = builder.GetConfiguration();
var export = new SchemaExport(config);
export.Drop(false, false);
export.Create(true, true);
}