Esempio n. 1
0
        ///<summary>
        ///字典左连接查询 使用,NavigateDicAttribute标记属性
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="select"></param>
        /// <returns></returns>
        public static ISelect <T> LeftJonDic <T>(this ISelect <T> select)
            where T : class
        {
            var responsitory = _services.BuildServiceProvider().GetService(typeof(ISysDicResponsitory)) as ISysDicResponsitory;
            var type         = typeof(T);

            foreach (var item in type.GetProperties())
            {
                var navDic = item.GetCustomAttribute(typeof(NavigateDicAttribute), false);
                if (navDic != null)
                {
                    var dicAttr    = navDic as NavigateDicAttribute;
                    var dicIdValue = responsitory.Where(p => p.Code == dicAttr.DicCode).First().Id;

                    var target = Expression.Parameter(typeof(T), "p");

                    var dic = Expression.Property(target, item.Name);

                    var left  = Expression.Property(dic, "DicId");
                    var right = Expression.Constant(dicIdValue);
                    var body  = Expression.Equal(left, right);


                    var left1  = Expression.Property(dic, "Value");
                    var right1 = Expression.Property(target, dicAttr.FieldName);
                    var body1  = Expression.Equal(left1, right1);
                    var expre  = Expression.AndAlso(body1, body);

                    var lambda = Expression.Lambda <Func <T, bool> >(expre, target);
                    select = select.LeftJoin(lambda);
                }
            }
            return(select);
        }