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 static void Map(Configuration cfg) { cfg.AddInputStream(HbmSerializer.Default.Serialize(typeof(ServiceLogEntity).Assembly)); cfg.AddInputStream(HbmSerializer.Default.Serialize(typeof(Client).Assembly)); var mapper = new ConventionModelMapper(); mapper.Class <ArchiveOffer>(m => { m.Catalog("Farm"); m.Table("CoreArchive"); m.ManyToOne(i => i.PriceList, x => x.Column("PriceCode")); }); var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); cfg.AddDeserializedMapping(mapping, "AmpService.Models"); }
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); }
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); }
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 void Configure(string nHConfigFile, IEnumerable <Type> mappings, string dbPwd, string dbUser, string dbName, string server) { try { _cfg = new Configuration(); _cfg.Configure(nHConfigFile); var mapper = new ConventionModelMapper(); mapper.AddMappings(mappings); _cfg.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities()); SetCredentials(dbUser, dbPwd, dbName, server); } catch (Exception ex) { iQExceptionHandler.SetCaller(ex, "nHManager::Configure"); throw ex; } }
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 HbmMapping GetHbmMappings() { var mapper = new ConventionModelMapper(); var mappings = MappingAssembly.GetExportedTypes().Where(MappingTypeFinder).ToList(); mapper.AddMappings(mappings); mapper.ApplyNamingConventions(); if (AutoMappingOverride != null) { AutoMappingOverride(mapper); } var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); ShowOutputXmlMappings(mapping); return(mapping); }
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; }
public void TestExportSchemaByCode() { var config = new Configuration(); config.Configure("MySql.cfg.xml"); var mapper = new ConventionModelMapper(); mapper.AddMapping(new EmployeeMapping()); mapper.AddMapping(new StoreMapping()); mapper.AddMapping(new ProductMapping()); var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); Assert.IsNotNull(mapping); Console.WriteLine(mapping.AsString()); config.AddMapping(mapping); // test build schema var schemaExport = new SchemaExport(config); schemaExport.SetDelimiter(";"); //schemaExport.SetOutputFile("R:\\test.sql"); schemaExport.Execute(true, true, false); }