public EntityApp Build(DbFirstConfig config) { _config = config; _app = new EntityApp(); var log = _app.ActivationLog; _dbSettings = new DbSettings(_config.Driver, DbOptions.Default, _config.ConnectionString); _dbSettings.SetSchemas(_config.Schemas); var modelLoader = _config.Driver.CreateDbModelLoader(_dbSettings, log); _dbModel = modelLoader.LoadModel(); Util.Check(_dbModel.Tables.Count() > 0, "No tables found in the database. Code generation aborted."); // Prepare type generator _tempNamespace = "_dummy_" + _callCount++; // artificial unique namespace for dummy interface types // Construct model setup and model GenerateModulesAndAreas(); _entityModel = new EntityModel(_app); EntityModelBuilder.SetModel(_app, _entityModel); _entityModel.ClassesAssembly = new EntityClassesAssembly(); //generate entities and members GenerateEntities(); SetupPrimaryKeys(); GenerateReferenceMembers(); CreateIndexes(); SetupKeyMembers(); return _app; }
// constructors public Database(EntityApp app, DbSettings settings) { _app = app; Settings = settings; _driver = Settings.ModelConfig.Driver; _entityModel = app.Model; _timeService = _app.TimeService; //Set list of all schemas var allSchemas = app.Areas.Select(a => settings.ModelConfig.GetSchema(a)); settings.SetSchemas(allSchemas); //Check if model is shared bool modelIsShared = Settings.ModelConfig.Options.IsSet(DbOptions.ShareDbModel); lock (_lock) { //we need lock to prevent collision on shared model if (modelIsShared) DbModel = Settings.ModelConfig.SharedDbModel; if (DbModel == null) { var dbmBuilder = new DbModelBuilder(app.Model, settings.ModelConfig, app.ActivationLog); DbModel = dbmBuilder.Build(); if (modelIsShared) Settings.ModelConfig.SharedDbModel = DbModel; } }//lock //Save }
int _tableKeyIndex; //is used to generate unique index names #endregion Fields #region Constructors public DbModelBuilder(EntityModel entityModel, DbModelConfig config, MemoryLog log) { _entityModel = entityModel; _config = config; _log = log; _driver = _config.Driver; }
public static void PreprocessCommand(EntityModel model, LinqCommand command) { if (command.Info.Lambda != null) return; var preProc = new LinqCommandPreprocessor(); preProc.Preprocess(model, command); }
public void Init(EntityModel model) { if (_initialized) return; _initialized = true; foreach (var res in this.GroupResources) res.Init(model); }
public void Init(EntityModel model) { if (_initialized) return; _initialized = true; var entInfo = model.GetEntityInfo(EntityType); Util.Check(entInfo != null, "Entity {0} is not part of entity model.", EntityType); if (!string.IsNullOrWhiteSpace(Properties)) MemberMask = EntityMemberMask.Create(entInfo, Properties); }
public void BuildEntityClasses(EntityModel model) { _model = model; //Initialize static fields if (_baseEntityClass == null) { _baseEntityClass = typeof(EntityBase); _baseDefaultConstructor = _baseEntityClass.GetConstructor(Type.EmptyTypes); _baseConstructor = _baseEntityClass.GetConstructor(new Type[] { typeof(EntityRecord) }); _entityBase_Record = typeof(EntityBase).GetField("Record"); _entityRecord_GetValue = typeof(EntityRecord).GetMethods().First(m => m.Name == "GetValue" && m.GetParameters()[0].ParameterType == typeof(int)); _entityRecord_SetValue = typeof(EntityRecord).GetMethods().First(m => m.Name == "SetValue" && m.GetParameters()[0].ParameterType == typeof(int)); } //Build classes BuildClasses(); }
public void Init(EntityModel model) { if (_initialized) return; _initialized = true; // child activities AllChildActivities.UnionWith(ChildActivities); AllPermissions.AddRange(this.Permissions); foreach (var child in ChildActivities) { child.Init(model); AllChildActivities.UnionWith(child.AllChildActivities); AllPermissions.AddRange(child.AllPermissions); } //Permissions foreach (var perm in this.Permissions) { var entPerm = perm as EntityGroupPermission; if (entPerm != null) entPerm.Init(model); } Util.Check(!AllChildActivities.Contains(this), "Activity {0} is a child of itself, looping not allowed.", this.Name); }
public void BuildRuntimeData(EntityModel entityModel, Role role) { if(role.RuntimeData != null) return; role.Init(entityModel); role.RuntimeData = new RuntimeRoleData(); // get refs to 'all' sets var allChildRoles = role.RuntimeData.AllChildRoles; var allChildGrants = role.RuntimeData.GrantedActivities; allChildGrants.UnionWith(role.ActivityGrants); //initialize with direct grants //Process child roles; collect roles and grants foreach(var child in role.ChildRoles) if(allChildRoles.Add(child)) { BuildRuntimeData(entityModel, child); allChildRoles.UnionWith(child.RuntimeData.AllChildRoles); //merge child roles allChildGrants.UnionWith(child.RuntimeData.GrantedActivities); //merge all child grants } //check there's no circular parent/child relationships Util.Check(!allChildRoles.Contains(role), "Role {0} is an (indirect) child of itself.", role.Name); // Now we merged all activity grants from child roles into one flat set allChildRoles // All activity grants from this and all child roles are merged into allChildGrants // What we need to add to allChildGrants is grand-child activities - child activities // of direct grants for this role. If this role R has grant G on activity A, and activity // A has child activity B, then effectively role R is granted activity B through the same // grant G (or its clone). If grant G has conditions (filter, dynamic condition), // then activity B is granted to role R with the same conditions. // So we grant grand-child activities (B's) through clones of child grant G. foreach(var actGrant in role.ActivityGrants) { foreach(var grandChild in actGrant.Activity.AllChildActivities) { var grandChildGrand = actGrant.CreateSimilarGrant(grandChild); allChildGrants.Add(grandChildGrand); } } //Consolidate all permissions in one plane set of (grant/permission) tuples foreach(var grant in role.RuntimeData.GrantedActivities) { foreach(var perm in grant.Activity.Permissions) { role.RuntimeData.GrantedPermissions.Add(new GrantedPermission(perm, grant)); } } }
public void Extend(EntityModel model) { if(model.ModelState != EntityModelState.EntitiesConstructed) return; //Add tracking properties (IDs of UserTransaction records) to all registered entities foreach(var spec in UpdateStampColumns) { foreach(var type in spec.Types) { var entInfo = model.GetEntityInfo(type); if(entInfo == null) { model.App.ActivationLog.Error("Failed to find entity info for type {0}", type); continue; } if(!string.IsNullOrEmpty(spec.CreateIdPropertyName)) { var newMember = new EntityMemberInfo(entInfo, MemberKind.Column, spec.CreateIdPropertyName, typeof(Guid)); newMember.Attributes.Add(new TrackAttribute(TrackingActionType.Created)); } if(!string.IsNullOrEmpty(spec.UpdateIdPropertyName)) { var newMember = new EntityMemberInfo(entInfo, MemberKind.Column, spec.UpdateIdPropertyName, typeof(Guid)); newMember.Attributes.Add(new TrackAttribute(TrackingActionType.Updated)); } }//foreach type }// foreach spec }
public CacheQueryRewriter(EntityModel model, StringCaseMode caseMode) { _model = model; _caseMode = caseMode; }
public Expression InjectCloneMethod(EntityModel model, Expression queryExpression, ParameterExpression sessionParameter) { _model = model; _sessionParameter = sessionParameter; var newExpr = AnalyzeNode(queryExpression); return newExpr; }
public static bool IsEntity(this EntityModel model, Type type) { return(model.IsRegisteredEntityType(type)); }
public void Init(EntityModel model) { if (_initialized) return; _initialized = true; foreach (var role in this.ChildRoles) role.Init(model); foreach (var grant in this.ActivityGrants) grant.Activity.Init(model); }
private void Preprocess(EntityModel model, LinqCommand command) { _model = model; _command = command; _parameters = new List<ParameterExpression>(); //create parameters for (int i = 0; i < _command.Locals.Count; i++) { var prmExpr = _command.Locals[i]; var prm = prmExpr.NodeType == ExpressionType.Parameter ? (ParameterExpression)prmExpr : Expression.Parameter(prmExpr.Type, "@P" + i); _parameters.Add(prm); } var body = this.Visit(_command.Query.Expression); _command.Info.Lambda = Expression.Lambda(body, _parameters); }