public static SysField GetKeyField(this SysEntity entity, DataContext context) { string key_name = entity.GetKeyFieldName(); SysField field = context.FirstOrDefault <SysField>(f => (f.EntityId == entity.EntityId) && (f.FieldName == key_name)); if (field == null) { throw new ApplicationException(string.Format("没有找到主键字段:{0} -{1}", entity.EntityName, key_name)); } return(field); }
private static void LoadEntitySchema() { EntityCacheBase cache = EntityCacheBase.LoadCache(); using (List <SysEntity> .Enumerator enumerator = cache.SysEntity.GetEnumerator()) { while (enumerator.MoveNext()) { Func <SysMobileStepEntity, bool> predicate = null; SysEntity e = enumerator.Current; EntitySchema es = new EntitySchema(); bool? isHistory = e.IsHistory; es.IsHistory = isHistory.HasValue ? isHistory.GetValueOrDefault() : false; SysOneMoreRelation relation = e.ChildOneMoreRelations.FirstOrDefault <SysOneMoreRelation>(p => p.Is_Tree == true); if (relation != null) { es.TreeRelationFieldName = relation.ChildField.FieldName; } es.IsChangeTableVersion = false; if (predicate == null) { predicate = delegate(SysMobileStepEntity p) { long?entityId = p.EntityId; long num = e.EntityId; return((entityId.GetValueOrDefault() == num) && entityId.HasValue); }; } if (cache.SysMobileStepEntity.Where <SysMobileStepEntity>(predicate).Count <SysMobileStepEntity>() > 0) { es.IsChangeTableVersion = true; } es.EntityId = e.EntityId; es.EntityName = e.EntityName; es.KeyName = e.GetKeyFieldName(); es.EntityType = cache.GetEntityType(e.EntityId); es.DisplayName = e.GetDisplayFieldName(); int?privilegeMode = e.PrivilegeMode; es.PrivilegeMode = privilegeMode.HasValue ? privilegeMode.GetValueOrDefault() : -2147483647; privilegeMode = e.RequiredLevel; es.RequiredLevel = privilegeMode.HasValue ? privilegeMode.GetValueOrDefault() : -2147483647; LoadUniqueKey(es, e, cache); LoadFields(es, e, cache); LoadRelations(es, e, cache); Add(es); } } }
private void CopyActivityInstanceData() { List <SysTransitionInstance> list = this.AI.ToTransitionInstances.ToList <SysTransitionInstance>(); if (list.Count == 0) { throw new ApplicationException("没有进入此活动的转换实例"); } SysTransitionInstance instance = list[0]; SysEntity activityEntity = instance.PreActivityInstance.Activity.Process.ActivityEntity; EntityData data = new EntityCache(base.Manager).GetObject(activityEntity, instance.PreActivityInstanceId.Value); if (data != null) { string keyFieldName = activityEntity.GetKeyFieldName(); data[keyFieldName] = this.AI.ActivityInstanceId; string activityTypeField = "ActivityType"; if (activityEntity.Fields.ToList <SysField>().FirstOrDefault <SysField>(i => (i.FieldName == activityTypeField)) != null) { data[activityTypeField] = this.AI.Activity.ActivityType; } base.Manager.Insert(data); } }