コード例 #1
0
ファイル: BaseDal.cs プロジェクト: ChenglongMa/DNA_MES
        /// <summary>
        /// 通过关系获取另一实体类
        /// </summary>
        /// <typeparam name="TB">要获得的对象</typeparam>
        /// <typeparam name="TLink">特殊的关系类</typeparam>
        /// <param name="roleA">已知对象</param>
        /// <param name="exp">额外条件表达式</param>
        /// <returns>所求对象集合</returns>
        protected virtual List <TB> GetChildren <TB, TLink>(T roleA, Expression <Func <TB, bool> > exp = null)
            where TB : BaseModel, new() where TLink : BaseLink, new()
        {
            if (!IsExist(roleA))
            {
                throw new ArgumentException($"{typeof(T).Name}[{roleA.ObjId}]不存在", nameof(roleA));
            }

            Refresh(ref roleA);
            var children = DbClient.Queryable <TLink>().AS("L_" + typeof(T).Name + typeof(TB).Name)
                           .Where(l => l.RoleAId == roleA.ObjId).ToList();

            if (children.IsNullOrEmpty())
            {
                return(null);
            }

            var expTemp = new Expressionable <TB>();

            foreach (var link in children)
            {
                expTemp.Or(b => b.ObjId == link.RoleBId);
            }

            return(DbClient.Queryable <TB>().Where(expTemp.AndIF(exp != null, exp).ToExpression()).ToList());
        }