public void TestFixtureSetUp() { configuration = new Configuration(); configuration.SessionFactory() .Integrate.Using<SQLiteDialect>() .Connected.Using("Data source=testdb") .AutoQuoteKeywords() .LogSqlInConsole() .EnableLogFormattedSql(); var mapper = new ConventionModelMapper(); mapper.Class<Foo>(cm => { }); mapper.Class<Bar>(cm => { }); CustomizeMapping(mapper); var mappingDocument = mapper.CompileMappingForAllExplicitlyAddedEntities(); new XmlSerializer(typeof(HbmMapping)).Serialize(Console.Out, mappingDocument); configuration.AddDeserializedMapping(mappingDocument, "Mappings"); new SchemaExport(configuration).Create(true, true); sessionFactory = configuration.BuildSessionFactory(); using (var session = sessionFactory.OpenSession()) using (var tx = session.BeginTransaction()) { var foo = new Foo { Bars = CreateCollection() }; foo.Bars.Add(new Bar { Data = 1 }); foo.Bars.Add(new Bar { Data = 2 }); id = session.Save(foo); tx.Commit(); } sessionFactory.Statistics.IsStatisticsEnabled = true; }
static void Main(string[] args) { SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory); var mapper = new ConventionModelMapper(); mapper.Class<SomeAreaClass>(c => { c.Property(x => x.Area, m => { m.Type<MsSql2008GeographyType>(); m.NotNullable(true); }); }); var cfg = new Configuration() .DataBaseIntegration(db => { db.ConnectionString = "YourConnectionString"; db.Dialect<MsSql2012GeographyDialect>(); }); cfg .AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities()); cfg .AddAuxiliaryDatabaseObject(new SpatialAuxiliaryDatabaseObject(cfg)); new SchemaExport(cfg).Execute(false, true, false); }
public static ISessionFactory GetSessionFactory() { var config = new Configuration(); config.SessionFactory().Integrate.Using<SQLiteDialect>().Connected.Using("Data source=nhtest.sqlite").AutoQuoteKeywords(); var mapper = new ConventionModelMapper(); Map(mapper); config.AddDeserializedMapping(mapper.CompileMappingForAllExplicitlyAddedEntities(), "Mappings"); SchemaMetadataUpdater.QuoteTableAndColumns(config); new SchemaUpdate(config).Execute(false, true); return config.BuildSessionFactory(); }
public static ISessionFactory GetSessionFactory() { AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; var config = new Configuration(); //config.SessionFactory().Integrate.Using<SQLiteDialect>().Connected.Using("Data source=nhtest.sqlite").AutoQuoteKeywords(); config.SessionFactory().Integrate.Using<SQLiteDialect>().Connected.Using(String.Format("Data source={0}", Path.Combine(clientPath, "nhtest.sqlite"))).AutoQuoteKeywords(); var mapper = new ConventionModelMapper(); Map(mapper); config.AddDeserializedMapping(mapper.CompileMappingForAllExplicitlyAddedEntities(), "Mappings"); SchemaMetadataUpdater.QuoteTableAndColumns(config); new SchemaUpdate(config).Execute(false, true); return config.BuildSessionFactory(); }
private HbmMapping GetMappingWithParentInCompo() { var mapper = new ConventionModelMapper(); mapper.Class<MyClass>(x => { x.Id(c => c.Id); x.Component(c => c.Compo); }); mapper.Component<MyCompo>(x => { x.Property(c => c.Something); }); return mapper.CompileMappingForAllExplicitlyAddedEntities(); }
public void TestFixtureSetUp() { var configuration = new Configuration(); configuration.SessionFactory() .Integrate.Using<SQLiteDialect>() .Connected.Using("Data source=testdb") .AutoQuoteKeywords() .LogSqlInConsole() .EnableLogFormattedSql(); var mapper = new ConventionModelMapper(); MapClasses(mapper); var mappingDocument = mapper.CompileMappingForAllExplicitlyAddedEntities(); new XmlSerializer(typeof(HbmMapping)).Serialize(Console.Out, mappingDocument); configuration.AddDeserializedMapping(mappingDocument, "Mappings"); new SchemaExport(configuration).Create(true, true); sessionFactory = configuration.BuildSessionFactory(); }
private static void InitSessionFactory(ServiceContext context) { var cfg = new Configuration(); var mapper = new ConventionModelMapper(); mapper.BeforeMapClass += (inspector, type, map) => { var idProperty = type.GetProperty("Id"); map.Id(idProperty, idMapper => { }); }; mapper.BeforeMapProperty += (inspector, propertyPath, map) => map.Column(propertyPath.ToColumnName()); mapper.BeforeMapManyToOne += (inspector, propertyPath, map) => map.Column(propertyPath.ToColumnName() + "Id"); foreach (var plugin in context.GetAllPlugins()) { plugin.InitDbModel(mapper); cfg.AddAssembly(plugin.GetType().Assembly); } var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); cfg.DataBaseIntegration(dbConfig => { dbConfig.Dialect<MsSqlCe40Dialect>(); dbConfig.Driver<SqlServerCeDriver>(); dbConfig.ConnectionStringName = "common"; }); cfg.AddDeserializedMapping(mapping, null); //Loads nhibernate mappings var sessionFactory = cfg.BuildSessionFactory(); context.InitSessionFactory(sessionFactory); }
public Configuration BuildConfiguration() { var mapper = new ConventionModelMapper(); CollectMappingContributorsAndApply(mapper); AR.RaiseOnMapperCreated(mapper, this); var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); mapping.autoimport = Source.AutoImport; mapping.defaultlazy = Source.Lazy; if (Source.Debug) { try { File.WriteAllText( Path.Combine( AppDomain.CurrentDomain.BaseDirectory, Name + "mapping.hbm.xml" ), mapping.AsString() ); } catch { /* just bail out */ } } AR.RaiseOnHbmMappingCreated(mapping, this); var cfg = new Configuration(); if (Source.NamingStrategyImplementation != null) cfg.SetNamingStrategy((INamingStrategy) Activator.CreateInstance(Source.NamingStrategyImplementation)); foreach(var key in Properties.AllKeys) { cfg.Properties[key] = Properties[key]; } CollectAllContributorsAndRegister(cfg); cfg.AddMapping(mapping); AR.RaiseOnConfigurationCreated(cfg, this); return cfg; }
static Configuration BuildSessionFactory() { var config = new Configuration(); config.SetProperties(CreateSessionFactoryDefaultProperties()); config.SetProperty(NhCfgEnv.ConnectionString, "Data Source=db-dev4.gdepb.gov.cn;Initial Catalog=Test;Persist Security Info=True;User ID=udev;Password=devdev"); var mapper = new ConventionModelMapper(); mapper.AddMapping(new UserMapping()); mapper.AddMapping(new RoleMapping()); var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); config.AddMapping(mapping); return config; }