Exemple #1
0
 // TODO: performance
 private static IEntity findByIdFromChild(int id, EntityInfo entityInfo)
 {
     foreach (EntityInfo ei in entityInfo.ChildEntityList)
     {
         IEntity result = ObjectDb.FindById(id, new ObjectInfo(ei));
         if (result != null)
         {
             return(result);
         }
     }
     return(null);
 }
Exemple #2
0
        private static IEntity setEntityProperty(IEntity obj, int id, ObjectInfo state)
        {
            if (obj == null)
            {
                return(null);
            }

            IList entityPropertyList = state.EntityInfo.EntityPropertyList;

            foreach (EntityPropertyInfo ep in entityPropertyList)
            {
                if (!isPropertyInIncluder(ep, state.Includer.EntityPropertyList))
                {
                    continue;
                }

                IEntity propertyValue = obj.get(ep.Name) as IEntity;
                if (propertyValue == null)
                {
                    continue;
                }

                int pid = propertyValue.Id;
                if (pid <= 0)
                {
                    continue;
                }


                IEntity cachedValue = ObjectPool.FindOne(ep.Type, pid);
                if (cachedValue == null)
                {
                    propertyValue = ObjectDb.FindById(pid, new ObjectInfo(ep.Type));

                    ObjectPool.Add(propertyValue);
                }
                else
                {
                    propertyValue = cachedValue;
                }

                ValueSetter.setEntityByCheckNull(obj, ep, propertyValue, pid);
            }

            return(obj);
        }
Exemple #3
0
        /// <summary>
        /// 根据 id 查询对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="id"></param>
        /// <returns></returns>
        public static T findById <T>(int id) where T : IEntity
        {
            if (id < 0)
            {
                return(default(T));
            }

            IEntity objCache = ObjectPool.FindOne(typeof(T), id);

            if (objCache == null)
            {
                ObjectInfo state = new ObjectInfo(typeof(T));
                objCache = ObjectDb.FindById(id, state);
                ObjectPool.Add(objCache);
            }

            return((T)objCache);
        }