Ejemplo n.º 1
0
        public override IQuery <T> WhereWithAnd(Expression <Func <T, bool> > expression)
        {
            var queryExpression = LambdaExpressionExtend.ResolveLambdaQueryExpression(expression);

            _query = QueryExpression.And(_query, queryExpression);
            return(this);
        }
Ejemplo n.º 2
0
        public override IAggregate <K> HavingWithAnd(Expression <Func <K, bool> > expression)
        {
            var queryExpression = LambdaExpressionExtend.ResolveLambdaHavingExpression(expression, Model);

            _having = QueryExpression.And(_having, queryExpression);
            return(this);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 添加查询表达式
 /// </summary>
 /// <param name="expression">查询表达式</param>
 /// <param name="catchType">连接操作符类型</param>
 /// <returns> 枚举查询器</returns>
 public LEnumerable <T> Where(QueryExpression expression, CatchOperatorsType catchType)
 {
     if (catchType == CatchOperatorsType.AND)
     {
         _query = QueryExpression.And(_query, expression);
     }
     else
     {
         _query = QueryExpression.Or(_query, expression);
     }
     return(this);
 }
Ejemplo n.º 4
0
        public object ToProperty(DataContext context, object source, bool exceptOwner)
        {
            InitialRelateMapping();
            QueryExpression expression = null;

            for (var i = 0; i < masterFieldMappings.Length; i++)
            {
                var             info          = relateInfos[i];
                var             field         = masterFieldMappings[i];
                QueryExpression keyExpression = new LightBinaryQueryExpression(relateEntityMapping, QueryPredicate.Eq, info, field.Handler.Get(source));
                expression = QueryExpression.And(expression, keyExpression);
            }

            object target = null;

            if (defaultConstructorInfo != null)
            {
                object[] args = { context, source, expression, exceptOwner ? fieldPaths : null };
                target = defaultConstructorInfo.Invoke(args);
            }
            return(target);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 读取关联数据
        /// </summary>
        /// <param name="keyName">关联字段属性名称</param>
        /// <param name="extendQuery">扩展查询</param>
        /// <param name="extendOrder">扩展排序</param>
        /// <returns>关联数据</returns>
        private object LoadRelationData(string keyName, QueryExpression extendQuery, OrderExpression extendOrder)
        {
            DataEntityMapping    selfMapping     = DataMapping.GetEntityMapping(this.GetType());
            RelationFieldMapping relationMapping = selfMapping.FindRelateionMapping(keyName);
            QueryExpression      expression      = null;

            foreach (RelationFieldMapping.RelationKeyValue rt in relationMapping.GetRelationKeyValues())
            {
                DataFieldInfo info   = new DataFieldInfo(relationMapping.RelateTableMapping.ObjectType, rt.RelateField.Name);
                object        objkey = rt.MasterField.Handler.Get(this);
                if (Object.Equals(objkey, null))
                {
                    expression &= info.IsNull();
                }
                else
                {
                    expression &= info == objkey;
                }
            }
            if (extendQuery != null)
            {
                expression = QueryExpression.And(expression, extendQuery);
            }
            //判断与关联表的关联关系
            if (relationMapping.Kind == RelationFieldMapping.RelationKind.OneToOne)
            {
                //一对一关系,直接查询单个对象
                object     obj = this.Context.SelectSingle(relationMapping.RelateTableMapping, expression, extendOrder, 0, SafeLevel.None);
                DataEntity de  = obj as DataEntity;
                if (de == null)
                {
                    return(obj);
                }
                if (relationMapping.RelateRelationMapping != null)                  //判断是否相互关联
                {
                    if (relationMapping.RelateRelationMapping.Kind == RelationFieldMapping.RelationKind.OneToOne)
                    {
                        de.TempRelationDatas.Add(relationMapping.RelateRelationMapping.RelationName, this);
                    }
                }
                return(de);
            }
            else
            {
                IList list = this.Context.QueryDataList(relationMapping.RelateTableMapping, expression, extendOrder, null, SafeLevel.Default) as IList;
                //if (list.Count == 0) return list;

                if (relationMapping.RelateRelationMapping != null && relationMapping.RelateRelationMapping.MasterTableMapping.IsDataEntity)
                {
                    if (relationMapping.RelateRelationMapping.Kind == RelationFieldMapping.RelationKind.OneToOne)
                    {
                        foreach (object obj in list)
                        {
                            DataEntity de = obj as DataEntity;
                            de.TempRelationDatas.Add(relationMapping.RelateRelationMapping.RelationName, this);
                        }
                    }
                }
                if (relationMapping.ResultDataKind == RelationFieldMapping.DataKind.IList)
                {
                    return(list);
                }
                else
                {
                    Array array = Array.CreateInstance(relationMapping.RelateTableMapping.ObjectType, list.Count);
                    list.CopyTo(array, 0);
                    return(array);
                }
            }
        }