예제 #1
0
        public override IEnumerable <FreeDocument> Generate(IFreeDocument document = null)
        {
            var mount = 0;

            if (Mount < 0)
            {
                mount = int.MaxValue;
            }
            TableInfo table = TableNames.SelectItem;

            if (table != null)
            {
                var con = new VirtualDataCollection(table.GetVirtualProvider <IFreeDocument>());
                foreach (var item in con.ComputeData.Skip(Position).Take(mount).Select(d => d.DictSerialize()))
                {
                    yield return(item);
                }
            }
        }
예제 #2
0
        /// <summary>
        ///     获取一定范围的实体
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="type"></param>
        /// <param name="mount"></param>
        /// <param name="skip"></param>
        /// <returns></returns>
        public override IEnumerable <IFreeDocument> GetEntities(
            string tableName, Type type, int mount = -1, int skip = 0)
        {
            if (IsUseable == false)
            {
                yield break;
            }
            if (TableNames == null)
            {
                IsUseable = false;
                yield break;
            }
            if (TableNames == null)
            {
                IsUseable = false;
                yield break;
            }
            TableInfo table = TableNames.Collection.FirstOrDefault(d => d.Name == tableName);

            if (table == null)
            {
                yield break;
            }

            ICursor <Document> collection = null;

            if (table.ColumnInfos != null && table.ColumnInfos.FirstOrDefault(d => d.Name == AutoIndexName) != null)
            {
                var query = new Document();

                query[AutoIndexName] = new Document("$gt", skip);


                collection = DB.GetCollection <Document>(tableName).Find(query).Sort(AutoIndexName, IndexOrder.Ascending);
            }
            else
            {
                collection = DB.GetCollection <Document>(tableName).FindAll();
                if (skip != 0)
                {
                    collection.Skip(skip);
                }
            }
            if (mount != -1)
            {
                collection = collection.Limit(mount);
            }


            foreach (Document document in collection.Documents)
            {
                IFreeDocument data = null;
                if (type == null)
                {
                    data = new FreeDocument();
                }
                else
                {
                    data = (IFreeDocument)Activator.CreateInstance(type);
                }


                data.DictDeserialize(document);
                yield return(data);
            }
        }