private static void LoadRelations(EntitySchema es, SysEntity entity, EntityCacheBase cache)
        {
            List <SysMoreMoreRelation> list = cache.SysMoreMoreRelation.Where <SysMoreMoreRelation>(delegate(SysMoreMoreRelation s) {
                long?childEntityId = s.ChildEntityId;
                long entityId      = entity.EntityId;
                return(((childEntityId.GetValueOrDefault() == entityId) && childEntityId.HasValue) || (((childEntityId = s.ParentEntityId).GetValueOrDefault() == (entityId = entity.EntityId)) && childEntityId.HasValue));
            }).ToList <SysMoreMoreRelation>();

            foreach (SysMoreMoreRelation relation in list)
            {
                long oid = relation.ParentEntityId.Value;
                if (oid == entity.EntityId)
                {
                    oid = relation.ChildEntityId.Value;
                }
                SysEntity entity2 = (from s in cache.SysEntity
                                     where s.EntityId == oid
                                     select s).FirstOrDefault <SysEntity>();
                if (entity2 == null)
                {
                    throw new ApplicationException(oid.ToString());
                }
                es.MmTables.Add(entity2.EntityName + "s", relation.TableName);
                ReferencedObject item = new ReferencedObject {
                    EntityType     = cache.GetEntityType(entity2.EntityId),
                    ReferenceField = entity2.EntityName + "s",
                    DeleteFlag     = DeleteFlag.SetNull,
                    ReferenceType  = ReferenceType.MoreMore
                };
                es.ReferencedObjectList.Add(item);
            }
        }
        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);
                }
            }
        }