public void PreInitialize(EntityContextPreInitializeContext context) { foreach (var initer in initializers) { initer.PreInitialize(context); } }
public void PreInitialize(EntityContextPreInitializeContext context) { _initializers.ForEach(s => { var watch = Stopwatch.StartNew(); s.PreInitialize(context); Tracer.Debug($"The {s.GetType().Name} was initialized ({watch.ElapsedMilliseconds}ms)."); }); }
void IEntityContextPreInitializer.PreInitialize(EntityContextPreInitializeContext context) { foreach (var map in context.Mappers) { if (_entityTypes != null && _entityTypes.Count != 0 && !_entityTypes.Contains(map.EntityType)) { continue; } var pk = PropertyUnity.GetPrimaryProperties(map.EntityType).FirstOrDefault(s => s.Info.GenerateType != IdentityGenerateType.None); if (pk == null) { continue; } var database = context.EntityContext.Database; var metadata = EntityMetadataUnity.GetEntityMetadata(map.EntityType); var tableName = metadata.TableName.ToUpper(); var columnName = pk.Info.FieldName.ToUpper(); var sequenceName = FixSequenceName(tableName, columnName); //创建序列 SqlCommand sql = $"SELECT 1 FROM USER_SEQUENCES WHERE SEQUENCE_NAME = '{sequenceName}'"; var result = database.ExecuteScalar(sql); //不存在的话先创建序列 if (result == DBNull.Value || result == null) { //取表中该列的最大值 + 1 sql = $"SELECT MAX({columnName}) FROM {tableName}"; var value = database.ExecuteScalar <int>(sql) + 1; sql = @"CREATE SEQUENCE {sequenceName} START WITH {value}"; database.ExecuteNonQuery(sql); } //创建触发器 sql = $"SELECT 1 FROM ALL_TRIGGERS WHERE TRIGGER_NAME = 'TRIG_{tableName}'"; result = database.ExecuteScalar(sql); //不存在的话先创建序列 if (result == DBNull.Value || result == null) { sql = $@" CREATE OR REPLACE TRIGGER TRIG_{tableName} BEFORE INSERT ON {tableName} FOR EACH ROW WHEN (NEW.{columnName} IS NULL OR NEW.{columnName} = 0) BEGIN SELECT {sequenceName}.NEXTVAL INTO:NEW.{columnName} FROM DUAL; END;"; database.ExecuteNonQuery(sql); } pk.Info.GenerateType = IdentityGenerateType.None; } }
void IEntityContextPreInitializer.PreInitialize(EntityContextPreInitializeContext context) { if (context.Mappers.Count > 0) { var contextType = context.ContextService.ContextType; var injection = context.ContextService.Provider.GetService <IInjectionProvider>(); context.Mappers.GroupBy(s => s.EntityType.Assembly) .Select(s => new { assembly = s.Key, types = s.Select(t => t.EntityType).Distinct().ToArray() }) .ForEach(s => EntityProxyManager.CompileAll(contextType, s.assembly, s.types, injection)); } }
void IEntityContextPreInitializer.PreInitialize(EntityContextPreInitializeContext context) { if (context.Mappers.Count > 0) { var injection = context.Service.Provider.GetService <IInjectionProvider>(); foreach (var assembly in context.Mappers.GroupBy(s => s.EntityType.Assembly)) { EntityProxyManager.CompileAll(assembly.Key, injection); } } }
void IEntityContextPreInitializer.PreInitialize(EntityContextPreInitializeContext context) { if (!(context.ContextService is IDatabaseAware aware)) { return; } var tbGen = context.ContextService.Provider.GetTableGenerateProvider(); if (tbGen != null) { context.Mappers.ForEach(s => TryCreate(context.ContextService, aware.Database, tbGen, s.EntityType)); } }
void IEntityContextPreInitializer.PreInitialize(EntityContextPreInitializeContext context) { var tbGen = context.Service.Provider.GetTableGenerateProvider(); context.Mappers.ForEach(s => TryCreate(context.Service, tbGen, s.EntityType)); }