Exemple #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);
            }
        }
Exemple #2
0
        public async override Task <List <K> > ToListAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            QueryCommand queryCommand = _context.Database.QuerySingleField(_context, SpecifiedFieldInfo, _query, _order, false, _region);
            DataDefine   define       = DataDefine.GetDefine(typeof(K));

            return(await _context.QueryDataDefineListAsync <K>(define, _level, queryCommand.Command, queryCommand.InnerPage?null : _region, null, null, cancellationToken));
        }
Exemple #3
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));
        }
Exemple #4
0
        public override List <K> ToList()
        {
            QueryCommand queryCommand = _context.Database.QuerySingleField(_context, SpecifiedFieldInfo, _query, _order, false, _region);
            DataDefine   define       = DataDefine.GetDefine(typeof(K));

            return(_context.QueryDataDefineList <K>(define, _level, queryCommand.Command, queryCommand.InnerPage ? null : _region, null, null));
        }
        public override IEnumerator <K> GetEnumerator()
        {
            var queryCommand = _context.Database.QuerySingleField(_context, SpecifiedFieldInfo, _query, _order, false, _region);
            var define       = DataDefine.GetDefine(typeof(K));

            return(_context.QueryDataDefineReader <K>(define, _level, queryCommand.Command, queryCommand.InnerPage ? null : _region, null, null).GetEnumerator());
        }
Exemple #6
0
        public override K ElementAt(int index)
        {
            Region       region       = new Region(index, 1);
            QueryCommand queryCommand = _context.Database.QuerySingleField(_context, SpecifiedFieldInfo, _query, _order, false, region);
            DataDefine   define       = DataDefine.GetDefine(typeof(K));

            return(_context.QueryDataDefineSingle <K>(define, _level, queryCommand.Command, queryCommand.InnerPage ? 0 : region.Start, null, null));
        }
Exemple #7
0
        public async override Task <K> ElementAtAsync(int index, CancellationToken cancellationToken = default(CancellationToken))
        {
            Region       region       = new Region(index, 1);
            QueryCommand queryCommand = _context.Database.QuerySingleField(_context, SpecifiedFieldInfo, _query, _order, false, region);
            DataDefine   define       = DataDefine.GetDefine(typeof(K));

            return(await _context.QueryDataDefineSingleAsync <K>(define, _level, queryCommand.Command, queryCommand.InnerPage? 0 : region.Start, null, null, cancellationToken));
        }
Exemple #8
0
        public override async Task <bool> ExistsAsync(CancellationToken cancellationToken = default)
        {
            var queryCommand = _context.Database.Exists(_context, _mapping, _query);
            var define       = DataDefine.GetDefine(typeof(int?));
            var obj          = await _context.QueryDataDefineSingleAsync <int?>(define, _level, queryCommand.Command, 0, null, null, cancellationToken);

            return(obj.HasValue);
        }
Exemple #9
0
        public override bool Exists()
        {
            var queryCommand = _context.Database.Exists(_context, _mapping, _query);
            var define       = DataDefine.GetDefine(typeof(int?));
            var obj          = _context.QueryDataDefineSingle <int?>(define, _level, queryCommand.Command, 0, null, null);

            return(obj.HasValue);
        }
Exemple #10
0
        private static DataDefine TransferDataDefine(DataFieldMapping fieldMapping)
        {
            DataDefine define = null;

            if (fieldMapping is PrimitiveFieldMapping)
            {
                if (fieldMapping.ObjectType == typeof(string))
                {
                    define = PrimitiveDataDefine.CreateString(fieldMapping.IsNullable, fieldMapping.Name);
                }
                else
                {
                    if (fieldMapping.IsNullable)
                    {
                        Type itemstype = System.Type.GetType("System.Nullable`1");
                        Type type      = itemstype.MakeGenericType(fieldMapping.ObjectType);
                        define = PrimitiveDataDefine.Create(type, fieldMapping.Name);
                    }
                    else
                    {
                        define = PrimitiveDataDefine.Create(fieldMapping.ObjectType, fieldMapping.Name);
                    }
                }
            }
            else
            if (fieldMapping is EnumFieldMapping)
            {
                EnumFieldMapping em = fieldMapping as EnumFieldMapping;
                if (fieldMapping.IsNullable)
                {
                    Type itemstype = System.Type.GetType("System.Nullable`1");
                    Type type      = itemstype.MakeGenericType(fieldMapping.ObjectType);
                    define = EnumDataDefine.Create(type, em.EnumType, fieldMapping.Name);
                }
                else
                {
                    define = EnumDataDefine.Create(fieldMapping.ObjectType, em.EnumType, fieldMapping.Name);
                }
            }
            else
            {
                throw new LightDataException(RE.OnlyPrimitiveFieldCanSelectSingle);
            }
            return(define);
        }
Exemple #11
0
        private static DataDefine TransferDataDefine(Type dataType, string name, bool isNullable)
        {
            DataDefine define = null;

            if (dataType == typeof(string))
            {
                define = PrimitiveDataDefine.CreateString(isNullable, name);
            }
            else
            {
                if (isNullable)
                {
                    Type itemstype = System.Type.GetType("System.Nullable`1");
                    Type type      = itemstype.MakeGenericType(dataType);
                    define = PrimitiveDataDefine.Create(type, name);
                }
                else
                {
                    define = PrimitiveDataDefine.Create(dataType, name);
                }
            }
            return(define);
        }
Exemple #12
0
 private SoloFieldDataMapping(Type type)
     : base(type)
 {
     dataDefine = DataDefine.GetDefine(type);
 }