コード例 #1
0
 private bool IsNullRelationshipAssignment(MappingEntity entity, EntityAssignment assignment)
 {
     if (this.mapping.IsRelationship(entity, assignment.Member))
     {
         ConstantExpression expression = assignment.Expression as ConstantExpression;
         if ((expression != null) && (expression.Value == null))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #2
0
        protected virtual ConstructorBindResult BindConstructor(ConstructorInfo cons, IList <EntityAssignment> assignments)
        {
            ParameterInfo[]            parameters = cons.GetParameters();
            Expression[]               arguments  = new Expression[parameters.Length];
            MemberInfo[]               members    = new MemberInfo[parameters.Length];
            HashSet <EntityAssignment> source     = new HashSet <EntityAssignment>(assignments);
            HashSet <EntityAssignment> other      = new HashSet <EntityAssignment>();
            int index  = 0;
            int length = parameters.Length;

            while (index < length)
            {
                Func <EntityAssignment, bool> predicate = null;
                ParameterInfo    p    = parameters[index];
                EntityAssignment item = source.FirstOrDefault <EntityAssignment>(a => (p.Name == a.Member.Name) && p.ParameterType.IsAssignableFrom(a.Expression.Type));
                if (item == null)
                {
                    if (predicate == null)
                    {
                        predicate = a => (string.Compare(p.Name, a.Member.Name, true) == 0) && p.ParameterType.IsAssignableFrom(a.Expression.Type);
                    }
                    item = source.FirstOrDefault <EntityAssignment>(predicate);
                }
                if (item != null)
                {
                    arguments[index] = item.Expression;
                    if (members != null)
                    {
                        members[index] = item.Member;
                    }
                    other.Add(item);
                }
                else
                {
                    MemberInfo[] member = cons.DeclaringType.GetMember(p.Name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
                    if ((member != null) && (member.Length > 0))
                    {
                        arguments[index] = Expression.Constant(King.Framework.Linq.TypeHelper.GetDefault(p.ParameterType), p.ParameterType);
                        members[index]   = member[0];
                    }
                    else
                    {
                        return(null);
                    }
                }
                index++;
            }
            source.ExceptWith(other);
            return(new ConstructorBindResult(Expression.New(cons, arguments, members), source));
        }
コード例 #3
0
        public override EntityExpression IncludeMembers(EntityExpression entity, Func <MemberInfo, bool> fnIsIncluded)
        {
            Dictionary <string, EntityAssignment> dictionary = this.GetAssignments(entity.Expression).ToDictionary <EntityAssignment, string>(ma => ma.Member.Name);
            bool flag = false;

            foreach (MemberInfo info in this.mapping.GetMappedMembers(entity.Entity))
            {
                EntityAssignment assignment;
                if (!(!(!dictionary.TryGetValue(info.Name, out assignment) || this.IsNullRelationshipAssignment(entity.Entity, assignment)) ? true : !fnIsIncluded(info)))
                {
                    assignment            = new EntityAssignment(info, this.GetMemberExpression(entity.Expression, entity.Entity, info));
                    dictionary[info.Name] = assignment;
                    flag = true;
                }
            }
            if (flag)
            {
                return(new EntityExpression(entity.Entity, this.BuildEntityExpression(entity.Entity, dictionary.Values.ToList <EntityAssignment>())));
            }
            return(entity);
        }