public void DynamicInsertShouldntOverrideDirectSetting() { new MappingTester <MappedObject>() .Conventions(conventions => conventions.Add(DynamicInsert.AlwaysTrue())) .ForMapping(c => c.Not.DynamicInsert()) .Element("class").HasAttribute("dynamic-insert", "false"); }
public MyAutoPersistenceModel() { this.AutoPersistenceModel = AutoMap.AssemblyOf <Entity>(new CustomAutomappingConfiguration()) .IgnoreBase <Entity>() .Override <User>(map => map.IgnoreProperty(x => x.DisplayedName)) .Override <Appointment>(map => map.IgnoreProperty(x => x.DateRange)) .Override <IllnessPeriod>(map => map.IgnoreProperty(p => p.Duration)) .Override <Role>(map => map.HasManyToMany(x => x.Tasks).Cascade.All()) .Override <DbSetting>(map => map.Map(p => p.Key).Unique()) .Override <Patient>(map => { map.DynamicUpdate(); map.IgnoreProperty(x => x.Age); map.Map(x => x.IsDeactivated).Default("0").Not.Nullable(); map.HasMany <Bmi>(x => x.BmiHistory).KeyColumn("Patient_Id"); map.HasMany <MedicalRecord>(x => x.MedicalRecords).KeyColumn("Patient_Id"); map.HasMany <IllnessPeriod>(x => x.IllnessHistory).KeyColumn("Patient_Id"); map.HasMany <Appointment>(x => x.Appointments).KeyColumn("Patient_Id"); }) .Override <Person>(map => { map.Map(p => p.FirstName).Index("idx_person_FirstName"); map.Map(p => p.LastName).Index("idx_person_LastName"); }) .Override <ApplicationStatistics>(map => { map.Map(e => e.IsExported).Default("0").Not.Nullable(); map.Map(e => e.Version).Default("\"3.0.3\"").Not.Nullable(); }) .Conventions.Add(DefaultCascade.SaveUpdate() , DynamicUpdate.AlwaysTrue() , DynamicInsert.AlwaysTrue() , LazyLoad.Always()); }
public void DynamicInsertShouldSetAttributeIfFalse() { new MappingTester <MappedObject>() .Conventions(conventions => conventions.Add(DynamicInsert.AlwaysFalse())) .ForMapping(c => { }) .Element("class").HasAttribute("dynamic-insert", "false"); }
public override void PreInitialize() { Configuration.Modules.AbpNHibernate().FluentConfiguration .Database(SQLiteConfiguration.Standard.InMemory()) .Mappings(m => m.FluentMappings .Conventions.Add( DynamicInsert.AlwaysTrue(), DynamicUpdate.AlwaysTrue() ) .AddFromAssembly(Assembly.GetExecutingAssembly()) ).ExposeConfiguration(cfg => new SchemaExport(cfg).Execute(true, true, false, IocManager.Resolve <DbConnection>(), Console.Out)); }
private void ConfigureMappings(MappingConfiguration config) { Database.Configuration.Mappings.ForEach(map => config.FluentMappings.AddFromAssembly(map)); config.FluentMappings.Conventions.Add <EnumConvention>(); config.FluentMappings.Conventions.Add <MonthConvention>(); config.FluentMappings.Conventions.Add( DefaultLazy.Always(), DefaultCascade.None(), DynamicInsert.AlwaysTrue(), DynamicUpdate.AlwaysTrue()); }
public ISessionFactory CreateFactory(string connectionString) { var nhibcfg = new NHibernate.Cfg.Configuration(); var cfg = Fluently.Configure(nhibcfg) .Database( PostgreSQLConfiguration .Standard .ConnectionString(connectionString) ) .Mappings(m => { m.AutoMappings.Add(AutoMap.AssemblyOf <Banan>(new AutomappingConfiguration()) .Conventions.Setup ( con => { con.Add <CommonConventions>(); con.Add(DefaultLazy.Never()); con.Add(DefaultCascade.SaveUpdate()); con.Add(DynamicInsert.AlwaysTrue()); con.Add(DynamicUpdate.AlwaysTrue()); }).UseOverridesFromAssemblyOf <OvverideMappingsFatherBanan>()); m.FluentMappings.Conventions.Add <CommonConventions>(); m.FluentMappings.Conventions.Add(DefaultLazy.Never(), DefaultCascade.SaveUpdate(), DynamicInsert.AlwaysTrue(), DynamicUpdate.AlwaysTrue()); m.MergeMappings(); }); if (true) { var directory = $"BananFatherDatabase.HBM"; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } cfg.Mappings(m => m.AutoMappings.ExportTo(directory)); } cfg.ExposeConfiguration(c => SchemaMetadataUpdater.QuoteTableAndColumns(c, new PostgreSQLDialect())); cfg.ExposeConfiguration(c => c.SetProperty("command_timeout", "30")); cfg.ExposeConfiguration(x => { x.SetInterceptor(new SqlStatementInterceptor()); }); UpdateSchema(cfg.BuildConfiguration()); return(cfg.BuildSessionFactory()); }
private void HandleMappings(MappingConfiguration cfg) { cfg.HbmMappings.AddFromAssemblyOf <SessionManager <T> >(); cfg.FluentMappings .AddFromAssembly(GetType().Assembly) .Conventions.AddAssembly(GetType().Assembly) .Conventions.Add( AutoImport.Always(), ForeignKey.EndsWith("ID"), LazyLoad.Always(), DefaultCascade.None(), DynamicInsert.AlwaysTrue(), DynamicUpdate.AlwaysTrue()); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); var persistenceModel = AutoMap.Assemblies( new AutoMappingConfiguration(), Enumerable.Empty <Assembly>()); persistenceModel .Conventions.AddAssembly(Assembly.GetExecutingAssembly()) .Conventions.Add( ConventionBuilder.Id.Always(x => x.Column("Id")), ForeignKey.EndsWith("Id"), ConventionBuilder.Property.When( x => x.Expect(y => y.ReadOnly), x => x.Access.CamelCaseField(FluentNHibernate.Conventions.Inspections.CamelCasePrefix.Underscore) ), DynamicInsert.AlwaysTrue(), DynamicUpdate.AlwaysTrue(), OptimisticLock.Is(x => x.Version())) .UseOverridesFromAssemblyOf <Startup>() .AddEntityAssembly(typeof(Startup).Assembly) .AddMappingsFromAssemblyOf <Startup>(); var sessionFactory = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008.ConnectionString(this.Configuration.GetConnectionString("Default"))) .ExposeConfiguration(config => { config.SetInterceptor(new AbpNHibernateInterceptor()); new SchemaValidator(config).Validate(); }) .Mappings( m => { m.AutoMappings.Add(persistenceModel); }) .BuildSessionFactory(); services.AddSingleton <ISessionFactory>(sessionFactory); }
public DatabaseFixture() { var databaseFileName = $"InstaLikeTestDb-{Guid.NewGuid()}.sqlite"; SessionFactory = Fluently.Configure() .Database( SQLiteConfiguration.Standard .ConnectionString(BuildTestDatabaseConnectionString(databaseFileName)) .AdoNetBatchSize(20) .ShowSql() .FormatSql() .UseReflectionOptimizer() ) .Mappings(m => m.FluentMappings .Conventions.Add( DefaultLazy.Always(), DynamicInsert.AlwaysTrue(), DynamicUpdate.AlwaysTrue(), new AssociationsMappingConvention(), new DateTimeOffsetTypeConvention() ) .Add <UserMapping>() .Add <FollowMapping>() .Add <PostMapping>() .Add <CommentMapping>() .Add <LikeMapping>() .Add <NotificationMapping>() ) .ExposeConfiguration(async cfg => { var schemaExport = new SchemaExport(cfg); schemaExport.SetOutputFile($"{databaseFileName}_Schema.sql"); await schemaExport.DropAsync(true, true); await schemaExport.CreateAsync(true, true); }) .BuildSessionFactory(); }
ISessionFactory CreateSessionFactory(ShardId shardId) { var shardNodes = ToolSection.Instance.TryGetNodes("shard/shardIds/shardId"); var shardNode = shardNodes.FirstOrDefault(o => o.Attributes.TryGetValue("id") == shardId.Id); if (shardNode == null) { throw new MissConfigurationException(ToolSection.Instance.RootNode, "shard/shardIds/shardId"); } var connectionName = shardNode.Attributes.TryGetValue("connectionName"); if (String.IsNullOrEmpty(connectionName)) { throw new ArgumentNullException("必须为分区 " + shardId.Id + " 指定数据源链接的名称路径 shard/shardIds/shardId/connectionName "); } var mysqlConfig = MySQLConfiguration.Standard .ConnectionString(p => p.FromConnectionStringWithKey(connectionName)) .AdoNetBatchSize(500) .Dialect <MySQL5Dialect>(); if (shardNode.TryGetValue("showSql") == "true") { mysqlConfig = mysqlConfig.ShowSql().FormatSql(); } List <Assembly> assemblies = SortAssemblyByDepend(RepositoryFramework.RepositoryAssemblies); var fluentConfig = Fluently.Configure().Database(mysqlConfig) .ProxyFactoryFactory <NHibernate.Bytecode.DefaultProxyFactoryFactory>() .CurrentSessionContext <NHibernate.Context.ManagedWebSessionContext>() .Mappings(p => { foreach (var assmebly in assemblies) { p.FluentMappings.AddFromAssembly(assmebly).Conventions.Add(DynamicInsert.AlwaysTrue(), DynamicUpdate.AlwaysTrue()); } //p.FluentMappings.ExportTo(@"C:\hmt"); }); Configuration cfg; try { cfg = fluentConfig.BuildConfiguration(); //var raiseEvent = new RaiseEventListener(); //cfg.AppendListeners(ListenerType.PreDelete, new IPreDeleteEventListener[] { raiseEvent }); //cfg.AppendListeners(ListenerType.PreUpdate, new IPreUpdateEventListener[] { raiseEvent }); //cfg.AppendListeners(ListenerType.PreDelete, new IPreDeleteEventListener[] { raiseEvent }); //cfg.AppendListeners(ListenerType.PostInsert, new IPostInsertEventListener[] { raiseEvent }); //cfg.AppendListeners(ListenerType.PostUpdate, new IPostUpdateEventListener[] { raiseEvent }); //cfg.AppendListeners(ListenerType.PostDelete, new IPostDeleteEventListener[] { raiseEvent }); //cfg.AppendListeners(ListenerType.PostLoad, new IPostLoadEventListener[] { raiseEvent }); } catch (Exception ex) { throw new SystemException("创建 NHibernate Configuration 发生错误:" + ex.Message, ex); } return(cfg.BuildSessionFactory()); }