예제 #1
0
        /// <summary>
        /// 根据关系属性构造查询表达式。
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="relationProperty"></param>
        /// <param name="thisKey"></param>
        /// <param name="otherKey"></param>
        /// <returns></returns>
        protected virtual Expression BuildRelationExpression(IEntity entity, RelationProperty relationProperty, Func <RelationshipKey, IProperty> thisKey, Func <RelationshipKey, IProperty> otherKey)
        {
            var relationKey = RelationshipUnity.GetRelationship(relationProperty);

            if (relationKey == null)
            {
                return(null);
            }

            var        parExp = Expression.Parameter(relationProperty.RelationType, "s");
            Expression binExp = null;

            foreach (var key in relationKey.Keys)
            {
                var val = entity.InternalGetValue(thisKey(key));
                if (PropertyValue.IsNullOrEmpty(val) || !val.IsValid)
                {
                    continue;
                }

                var member = otherKey(key).Info.ReflectionInfo;
                var mbrExp = Expression.MakeMemberAccess(parExp, member);
                var exp    = Expression.Equal(mbrExp, Expression.Constant(val.GetStorageValue()));
                binExp = binExp == null ? exp : Expression.And(binExp, exp);
            }

            if (binExp == null)
            {
                return(null);
            }

            return(Expression.Lambda(binExp, parExp));
        }
예제 #2
0
 /// <summary>
 /// 创建关联查询的表达式。
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="relationProperty"></param>
 /// <returns></returns>
 private Expression BuidRelationExpression(IEntity entity, RelationProperty relationProperty)
 {
     return(BuildRelationExpression(entity, relationProperty,
                                    new Func <RelationshipKey, IProperty>(k => k.OtherProperty),
                                    new Func <RelationshipKey, IProperty>(k => k.ThisProperty)));
 }