コード例 #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);
 }
コード例 #2
0
ファイル: ndb.cs プロジェクト: zuhuizou/wojilu
        /// <summary>
        /// 根据 id 查询对象
        /// </summary>
        /// <param name="t">对象的类型</param>
        /// <param name="id">对象的 id</param>
        /// <returns></returns>
        public static IEntity findById(Type t, long id)
        {
            if (id < 0)
            {
                return(null);
            }

            IEntity objCache = ObjectPool.FindOne(t, id);

            if (objCache == null)
            {
                ObjectInfo state = new ObjectInfo(t);
                objCache = ObjectDB.FindById(id, state);
                ObjectPool.Add(objCache);
            }
            return(objCache);
        }
コード例 #3
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);
        }
コード例 #4
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);
        }