コード例 #1
0
        /// <summary>
        /// 查询单列数据
        /// </summary>
        /// <param name="fieldInfo">字段信息</param>
        /// <param name="outputType">输出类型</param>
        /// <param name="isNullable">是否可空</param>
        /// <param name="query">查询表达式</param>
        /// <param name="order">排序表达式</param>
        /// <param name="region">查询范围</param>
        /// <param name="distinct">是否排除重复</param>
        /// <param name="level">安全级别</param>
        /// <returns>数据集合</returns>
        internal IList QueryColumeList(DataFieldInfo fieldInfo, Type outputType, bool isNullable, QueryExpression query, OrderExpression order, Region region, bool distinct, SafeLevel level)
        {
            using (IDbCommand command = _dataBase.Factory.CreateSelectSingleFieldCommand(fieldInfo, query, order, distinct, null))
            {
                DataDefine define = TransferDataDefine(outputType, null, isNullable);
                IList      items  = CreateList(define.ObjectType);

                IEnumerable ie = QueryDataReader(define, command, region, level);
                if (define.IsNullable)
                {
                    MethodInfo addMethod = items.GetType().GetMethod("Add");
                    foreach (object obj in ie)
                    {
                        if (Object.Equals(obj, null))
                        {
                            addMethod.Invoke(items, new object[] { null });
                        }
                        else
                        {
                            items.Add(obj);
                        }
                    }
                }
                else
                {
                    foreach (object obj in ie)
                    {
                        items.Add(obj);
                    }
                }
                return(items);
            }
        }
コード例 #2
0
        void LoadNormal()
        {
            List <DataFieldInfo> rootInfoList = new List <DataFieldInfo>();
            Selector             dataSelector = new Selector();

            foreach (DataFieldMapping fieldMapping in this.rootMapping.DataEntityFields)
            {
                if (fieldMapping != null)
                {
                    DataFieldInfo field = new DataFieldInfo(fieldMapping);
                    fieldInfoDict.Add(string.Format("{0}.{1}", string.Empty, fieldMapping.IndexName), field);
                    rootInfoList.Add(field);
                    dataSelector.SetSelectField(field);
                }
            }
            tableInfoDict.Add(string.Empty, rootInfoList.ToArray());
            string path = string.Empty;

            foreach (CollectionRelationFieldMapping collectFieldMapping in rootMapping.CollectionRelationFieldMappings)
            {
                RelationKey[] kps     = collectFieldMapping.GetKeyPairs();
                string[]      masters = new string[kps.Length];
                for (int i = 0; i < kps.Length; i++)
                {
                    masters[i] = string.Format("{0}.{1}", path, kps[i].MasterKey);
                }
                string collectField = string.Format("{0}.{1}", path, collectFieldMapping.FieldName);
                collectionDict.Add(collectField, masters);
            }
            this.selector = dataSelector;
        }
コード例 #3
0
        public override DataFieldInfo GetDataFieldInfo(string fullPath)
        {
            int index = fullPath.IndexOf(".", StringComparison.Ordinal);

            if (index < 0)
            {
                if (mapDict.TryGetValue(fullPath, out IMap map1))
                {
                    DataFieldInfo info           = map1.GetFieldInfoForPath(fullPath);
                    string        aliasTableName = aliasDict[fullPath];
                    info = info.CreateAliasTableInfo(aliasTableName);
                    return(info);
                }
                throw new LambdaParseException(LambdaParseMessage.ExpressionFieldPathError, fullPath);
            }
            string name = fullPath.Substring(0, index);
            string path = fullPath.Substring(index);

            if (mapDict.TryGetValue(name, out IMap map))
            {
                DataFieldInfo info           = map.GetFieldInfoForPath(path);
                string        aliasTableName = aliasDict[name];
                info = info.CreateAliasTableInfo(aliasTableName);
                return(info);
            }
            else
            {
                throw new LambdaParseException(LambdaParseMessage.ExpressionFieldPathNotExists, fullPath);
            }
        }
コード例 #4
0
        public ISelector CreateSelector(string [] paths)
        {
            var selector = new Selector();

            foreach (var path in paths)
            {
                var name = path.StartsWith(".", StringComparison.Ordinal) ? path.Substring(1) : path;
                if (name == string.Empty)
                {
                    var nameInfos = _model.GetDataFieldInfos();
                    foreach (var fieldInfo in nameInfos)
                    {
                        selector.SetSelectField(fieldInfo);
                    }
                }
                else
                {
                    var info = _model.GetFieldData(name);
                    if (!Equals(info, null))
                    {
                        var nameInfo = new DataFieldInfo(info.TableMapping, false, name);
                        selector.SetSelectField(nameInfo);
                    }
                    else
                    {
                        throw new LightDataException(string.Format(SR.CanNotFindTheSpecifiedFieldViaPath, path));
                    }
                }
            }
            return(selector);
        }
コード例 #5
0
        public void AddGroupByField(string name, DataFieldInfo fieldInfo)
        {
            _hasGroupBy = true;
            var agg = new AggregateDataFieldInfo(fieldInfo, name, false);

            _aggregateDict.Add(name, agg);
        }
コード例 #6
0
        /// <summary>
        /// 从主键获取数据对象
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="primaryKeys">主键数组</param>
        /// <returns>数据对象</returns>
        public T SelectSingleFromKey <T>(params object[] primaryKeys)
            where T : class, new()
        {
            DataTableEntityMapping dtmapping = DataMapping.GetTableMapping(typeof(T));

            if (primaryKeys.Length != dtmapping.PrimaryKeyFields.Length)
            {
                throw new LightDataException(RE.TheNumberOfPrimaryKeysIsNotMatch);
            }
            DataFieldInfo[] primaryKeyInfos = new DataFieldInfo[primaryKeys.Length];
            QueryExpression query           = null;

            for (int i = 0; i < primaryKeys.Length; i++)
            {
                primaryKeyInfos[i] = new DataFieldInfo(dtmapping.PrimaryKeyFields[i]);
                if (i == 0)
                {
                    query = primaryKeyInfos[i] == primaryKeys[i];
                }
                else
                {
                    query = query & primaryKeyInfos[i] == primaryKeys[i];
                }
            }
            return(SelectSingle(dtmapping, query, null, 0, SafeLevel.None) as T);
        }
コード例 #7
0
ファイル: RelationMap.cs プロジェクト: mingyaaaa/Light.Data2
        private void LoadNormal()
        {
            var rootInfoList = new List <DataFieldInfo>();
            var dataSelector = new Selector();

            foreach (var fieldMapping in RootMapping.DataEntityFields)
            {
                if (fieldMapping != null)
                {
                    var field = new DataFieldInfo(fieldMapping);
                    fieldInfoDict.Add($"{string.Empty}.{fieldMapping.IndexName}", field);
                    rootInfoList.Add(field);
                    dataSelector.SetSelectField(field);
                }
            }
            tableInfoDict.Add(string.Empty, rootInfoList.ToArray());
            var path = string.Empty;

            foreach (var collectFieldMapping in RootMapping.CollectionRelationFieldMappings)
            {
                var kps     = collectFieldMapping.GetKeyPairs();
                var masters = new string[kps.Length];
                for (var i = 0; i < kps.Length; i++)
                {
                    masters[i] = $"{path}.{kps[i].MasterKey}";
                }
                var collectField = $"{path}.{collectFieldMapping.FieldName}";
                collectionDict.Add(collectField, masters);
            }
            selector = dataSelector;
        }
コード例 #8
0
        /// <summary>
        /// 查询单列数据
        /// </summary>
        /// <param name="fieldInfo">字段信息</param>
        /// <param name="outputType">输出类型</param>
        /// <param name="isNullable">是否可空</param>
        /// <param name="query">查询表达式</param>
        /// <param name="order">排序表达式</param>
        /// <param name="region">查询范围</param>
        /// <param name="distinct">是否排除重复</param>
        /// <param name="level">安全级别</param>
        /// <returns>单列数据枚举</returns>
        internal IEnumerable QueryColumeEnumerable(DataFieldInfo fieldInfo, Type outputType, bool isNullable, QueryExpression query, OrderExpression order, Region region, bool distinct, SafeLevel level)
        {
            IDbCommand command = _dataBase.Factory.CreateSelectSingleFieldCommand(fieldInfo, query, order, distinct, null);
            DataDefine define  = TransferDataDefine(outputType, null, isNullable);

            return(QueryDataReader(define, command, region, level));
        }
コード例 #9
0
ファイル: LEnumerable.cs プロジェクト: LightRobot/Light.Data
 /// <summary>
 /// 查询单列字段的数据
 /// </summary>
 /// <param name="fieldInfo">字段</param>
 /// <param name="isDistinct">是否去重</param>
 /// <returns>数据枚举</returns>
 public IEnumerable QuerySingleField(DataFieldInfo fieldInfo, bool isDistinct)
 {
     if (!_mapping.Equals(fieldInfo.DataField.TypeMapping))
     {
         throw new LightDataException(RE.FieldIsNotMatchDataMapping);
     }
     return(_context.QueryColumeEnumerable(fieldInfo, _query, _order, _region, isDistinct, _level));
 }
コード例 #10
0
ファイル: Selector.cs プロジェクト: mingyaaaa/Light.Data2
 public virtual void SetSelectField(DataFieldInfo field)
 {
     if (Equals(field, null))
     {
         throw new ArgumentNullException(nameof(field));
     }
     selectList.Add(field);
 }
コード例 #11
0
 public LightSubQueryDataFieldInfo(DataEntityMapping mapping, DataFieldInfo field, DataFieldInfo selectField, QueryCollectionPredicate predicate, QueryExpression expression)
     : base(mapping)
 {
     _field       = field;
     _selectField = selectField;
     _predicate   = predicate;
     _expression  = expression;
 }
コード例 #12
0
 /// <summary>
 /// 统计最小值
 /// </summary>
 /// <param name="fieldInfo">统计字段</param>
 /// <returns>函数对象</returns>
 public static AggregateFunction Min(DataFieldInfo fieldInfo)
 {
     if (Object.Equals(fieldInfo, null))
     {
         throw new ArgumentNullException("fieldInfo");
     }
     return(new MinFunction(fieldInfo.TableMapping, fieldInfo));
 }
コード例 #13
0
 /// <summary>
 /// 对字段进行平均值统计
 /// </summary>
 /// <param name="fieldInfo">统计字段</param>
 /// <param name="isDistinct">是否去重复</param>
 /// <returns>函数对象</returns>
 public static AggregateFunction Avg(DataFieldInfo fieldInfo, bool isDistinct)
 {
     if (Object.Equals(fieldInfo, null))
     {
         throw new ArgumentNullException("fieldInfo");
     }
     return(new AvgFunction(fieldInfo.TableMapping, fieldInfo, isDistinct));
 }
コード例 #14
0
 public void SetInsertField(DataFieldInfo field)
 {
     if (Equals(field, null))
     {
         throw new ArgumentNullException(nameof(field));
     }
     insertList.Add(field);
 }
コード例 #15
0
ファイル: LEnumerable.cs プロジェクト: LightRobot/Light.Data
 /// <summary>
 /// 查询单列字段的数据
 /// </summary>
 /// <typeparam name="K">输出字段类型,必须为原始数据类型</typeparam>
 /// <param name="fieldInfo">字段</param>
 /// <param name="isNullable">是否可空</param>
 /// <param name="isDistinct">是否去重</param>
 /// <returns>数据集合</returns>
 public IList QuerySingleFieldList <K> (DataFieldInfo fieldInfo, bool isNullable, bool isDistinct)
 {
     if (!_mapping.Equals(fieldInfo.DataField.TypeMapping))
     {
         throw new LightDataException(RE.FieldIsNotMatchDataMapping);
     }
     return(_context.QueryColumeList(fieldInfo, typeof(K), isNullable, _query, _order, _region, isDistinct, _level));
 }
コード例 #16
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="dataField">要更新的数据字段</param>
 /// <param name="value">更新值</param>
 public UpdateSetValue(DataFieldInfo dataField, object value)
 {
     if (Object.Equals(dataField, null))
     {
         throw new ArgumentNullException("DataField");
     }
     _dataField = dataField;
     _value     = value;
 }
コード例 #17
0
 public LightContainsDataFieldInfo(DataFieldInfo info, object collection)
     : base(info.TableMapping)
 {
     if (collection == null)
     {
         throw new ArgumentNullException(nameof(collection));
     }
     this._collection    = collection;
     this._baseFieldInfo = info;
 }
コード例 #18
0
        public virtual DataFieldInfo [] GetDataFieldInfos()
        {
            DataFieldInfo [] infos = new DataFieldInfo [_selectDict.Count];
            int index = 0;

            foreach (KeyValuePair <string, DataFieldInfo> kvp in _selectDict)
            {
                infos [index] = kvp.Value;
                index++;
            }
            return(infos);
        }
コード例 #19
0
ファイル: SelectModel.cs プロジェクト: mingyaaaa/Light.Data2
        public DataFieldInfo [] GetDataFieldInfos()
        {
            var infos = new DataFieldInfo [_selectDict.Count];
            var index = 0;

            foreach (var kvp in _selectDict)
            {
                infos [index] = kvp.Value;
                index++;
            }
            return(infos);
        }
コード例 #20
0
 public DataFieldInfoRelation [] CreateDataFieldInfoRelations(string masterAlias, string relateAlias)
 {
     InitialRelateMapping();
     DataFieldInfoRelation [] array = new DataFieldInfoRelation [keyPairs.Length];
     for (int i = 0; i < keyPairs.Length; i++)
     {
         DataFieldInfo masterField = new DataFieldInfo(this.masterFieldMappings [i], masterAlias);
         DataFieldInfo relateField = new DataFieldInfo(this.relateFieldMappings [i], relateAlias);
         array [i] = new DataFieldInfoRelation(masterField, relateField);
     }
     return(array);
 }
コード例 #21
0
 public void AddSelectField(string name, DataFieldInfo fieldInfo)
 {
     if (name != fieldInfo.FieldName)
     {
         SpecifiedDataFieldInfo selectInfo = new SpecifiedDataFieldInfo(fieldInfo, name);
         _selectDict.Add(name, selectInfo);
     }
     else
     {
         _selectDict.Add(name, fieldInfo);
     }
 }
コード例 #22
0
 /// <summary>
 /// 匹配细节内容是否相等
 /// </summary>
 /// <param name="info">匹配对象</param>
 /// <returns></returns>
 protected override bool EqualsDetail(DataFieldInfo info)
 {
     if (base.EqualsDetail(info))
     {
         ExtendDataFieldInfo target = info as ExtendDataFieldInfo;
         return(this._baseFieldInfo.Equals(target._baseFieldInfo));
     }
     else
     {
         return(false);
     }
 }
コード例 #23
0
        public virtual QueryCommand Aggregate(DataContext context, DataFieldInfo field, AggregateType aggregateType, QueryExpression query, bool distinct)
        {
            CreateSqlState state        = new CreateSqlState(context);
            CommandData    commandData  = _factory.CreateAggregateFunctionCommand(field, aggregateType, query, distinct, state);
            DbCommand      command      = commandData.CreateCommand(this, state);
            QueryCommand   queryCommand = new QueryCommand()
            {
                Command   = command,
                InnerPage = commandData.InnerPage
            };

            return(queryCommand);
        }
コード例 #24
0
        public virtual QueryCommand QuerySingleField(DataContext context, DataFieldInfo fieldInfo, QueryExpression query, OrderExpression order, bool distinct, Region region)
        {
            CreateSqlState state        = new CreateSqlState(context);
            CommandData    commandData  = _factory.CreateSelectSingleFieldCommand(fieldInfo, query, order, distinct, region, state);
            DbCommand      command      = commandData.CreateCommand(this, state);
            QueryCommand   queryCommand = new QueryCommand()
            {
                Command   = command,
                InnerPage = commandData.InnerPage
            };

            return(queryCommand);
        }
コード例 #25
0
        public void SetDataField(DataFieldInfo field)
        {
            if (Object.Equals(field, null))
            {
                throw new ArgumentNullException(nameof(field));
            }
            AliasDataFieldInfo aliasField = new AliasDataFieldInfo(field, field.FieldName);

            this.infoDict [aliasField.AliasName] = aliasField;
            if (field.AliasTableName != null)
            {
                aliasTableHash.Add(field.AliasTableName);
            }
        }
コード例 #26
0
        /// <summary>
        /// 从自增ID获取数据对象
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="id">自增</param>
        /// <returns>数据对象</returns>
        private T SelectSingleFromIdObj <T>(object id)
            where T : class, new()
        {
            DataTableEntityMapping dtmapping = DataMapping.GetTableMapping(typeof(T));

            if (dtmapping.IdentityField == null)
            {
                throw new LightDataException(RE.DataTableNotIdentityField);
            }
            DataFieldInfo   idfield = new DataFieldInfo(dtmapping.IdentityField);
            QueryExpression query   = idfield == id;

            return(SelectSingle(dtmapping, query, null, 0, SafeLevel.None) as T);
        }
コード例 #27
0
ファイル: RelationMap.cs プロジェクト: mingyaaaa/Light.Data2
        private DataFieldInfo[] GetFieldInfoForSingleField(string path)
        {
            if (singleDict.TryGetValue(path, out var fields))
            {
                var infos = new DataFieldInfo[fields.Length];
                for (var i = 0; i < fields.Length; i++)
                {
                    infos[i] = GetFieldInfoForField(fields[i]);
                }
                return(infos);
            }

            throw new LightDataException(string.Format(SR.CanNotFindTheSpecifiedFieldViaPath, path));
        }
コード例 #28
0
 /// <summary>
 /// 对字段进行平均值条件统计
 /// </summary>
 /// <param name="expression">条件表达式</param>
 /// <param name="fieldInfo">统计字段</param>
 /// <param name="isDistinct">是否去重复</param>
 /// <returns>函数对象</returns>
 public static AggregateFunction Avg(QueryExpression expression, DataFieldInfo fieldInfo, bool isDistinct)
 {
     if (expression == null)
     {
         throw new ArgumentNullException("expression");
     }
     if (Object.Equals(fieldInfo, null))
     {
         throw new ArgumentNullException("fieldInfo");
     }
     if (!expression.IgnoreConsistency && !fieldInfo.TableMapping.Equals(expression.TableMapping))
     {
         throw new LightDataException(RE.DataMappingIsNotMatchQueryExpression);
     }
     return(new ConditionAvgFunction(fieldInfo.TableMapping, expression, fieldInfo, isDistinct));
 }
コード例 #29
0
 public void SetDataEntity(DataEntityMapping entityMapping)
 {
     if (entityMapping == null)
     {
         throw new ArgumentNullException(nameof(entityMapping));
     }
     foreach (DataFieldMapping fieldMapping in entityMapping.DataEntityFields)
     {
         if (fieldMapping != null)
         {
             DataFieldInfo      field      = new DataFieldInfo(fieldMapping);
             AliasDataFieldInfo aliasField = new AliasDataFieldInfo(field, field.FieldName);
             this.infoDict [aliasField.AliasName] = aliasField;
         }
     }
 }
コード例 #30
0
        public static JoinSelector ComposeSelector(Dictionary <string, Selector> selectors)
        {
            JoinSelector joinSelector = new JoinSelector();

            foreach (KeyValuePair <string, Selector> selector in selectors)
            {
                foreach (DataFieldInfo item in selector.Value.selectList)
                {
                    DataFieldInfo      info      = item;
                    string             aliasName = string.Format("{0}_{1}", selector.Key, info.FieldName);
                    AliasDataFieldInfo alias     = new AliasDataFieldInfo(info, aliasName, selector.Key);
                    //alias.AliasTableName = selector.Key;
                    joinSelector.SetAliasDataField(alias);
                }
            }
            return(joinSelector);
        }