/// <summary> /// 提醒DD动态更新的事件 /// </summary> /// <param name="msgObject">CQApi</param> private static void SubscriptionEvent(object msgObject) { if (msgObject is ConnectEventArgs connectEventArgs) { DynamicUpdate.BiliUpdateCheck(connectEventArgs); } }
public void DynamicUpdateShouldntOverrideDirectSetting() { new MappingTester <MappedObject>() .Conventions(conventions => conventions.Add(DynamicUpdate.AlwaysTrue())) .ForMapping(c => c.Not.DynamicUpdate()) .Element("class").HasAttribute("dynamic-update", "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 static IServiceCollection ConfigureDataAccess(this IServiceCollection services, string connectionString) { var nhConfig = Fluently.Configure() .Database( MsSqlConfiguration.MsSql2012.ConnectionString(connectionString) .DefaultSchema("dbo") .AdoNetBatchSize(20) .ShowSql() .FormatSql() .UseReflectionOptimizer() ) .Mappings(m => m.FluentMappings .Conventions.Add( LazyLoad.Always(), DynamicUpdate.AlwaysTrue()) .Conventions.Add <AssociationsMappingConvention>() .Conventions.Add <NotNullGuidTypeConvention>() .AddFromAssembly(Assembly.GetExecutingAssembly()) ); services.AddSingleton(nhConfig.BuildSessionFactory()); services.AddScoped(sp => { var sessionFactory = sp.GetRequiredService <ISessionFactory>(); return(sessionFactory.OpenSession()); }); return(services); }
public void DynamicUpdateShouldSetAttributeIfFalse() { new MappingTester <MappedObject>() .Conventions(conventions => conventions.Add(DynamicUpdate.AlwaysFalse())) .ForMapping(c => { }) .Element("class").HasAttribute("dynamic-update", "false"); }
protected override void Apply(IConventionFinder conventionFinder) { conventionFinder.Add <Dao.NHibernate.Extension.Convention.UpperCaseTableName.Convention>(); conventionFinder.Add <Dao.NHibernate.Extension.Convention.UpperCaseColumnName.Convention>(); //conventionFinder.Add<NHibernate.Extension.Convention.UpperCaseString.Convention>(); conventionFinder.Add(new Dao.NHibernate.Extension.Convention.TablePrefix.Convention("X")); conventionFinder.Add(new Dao.NHibernate.Extension.Convention.Eumeration.Convention()); conventionFinder.Add(DynamicUpdate.AlwaysTrue()); }
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 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)); }
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()); }
protected override void OnCreateDynamicUpdateMap(DynamicUpdate.NativeActivityUpdateMapMetadata metadata, Activity originalActivity) { // Our algorithm for recovering from update depends on iterating a unique Activities list. // So we can't support update if the same activity is referenced more than once. for (int i = 0; i < this.Activities.Count - 1; i++) { for (int j = i + 1; j < this.Activities.Count; j++) { if (this.Activities[i] == this.Activities[j]) { metadata.DisallowUpdateInsideThisActivity(SR.SequenceDuplicateReferences); break; } } } }
// 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); }
private static FluentConfiguration GetFluentConfigurationForDatabase(string connectionString) { return(Fluently.Configure() .Database( MsSqlConfiguration.MsSql2012 .Provider <HybridStorageDriverConnectionProvider>() .ConnectionString(connectionString) .DefaultSchema("dbo") .AdoNetBatchSize(20) .ShowSql() .FormatSql() .UseReflectionOptimizer() ) .Mappings(m => m.FluentMappings .Conventions.Add( LazyLoad.Always(), DynamicUpdate.AlwaysTrue()) .Conventions.Add <AssociationsMappingConvention>() .Conventions.Add <NotNullGuidTypeConvention>() .AddFromAssembly(Assembly.GetExecutingAssembly()))); }
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(); }
/// <summary> /// 提醒DD动态更新的事件 /// </summary> /// <param name="apiObject">CQApi</param> private void SubscriptionEvent(object apiObject) { CQApi cqApi = (CQApi)apiObject; DynamicUpdate.BiliUpdateCheck(cqApi); }
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()); }
protected override void OnCreateDynamicUpdateMap(DynamicUpdate.NativeActivityUpdateMapMetadata metadata, Activity originalActivity) { metadata.AllowUpdateInsideThisActivity(); }