Esempio n. 1
0
        /// <summary>
        /// 获取给定的 <see cref="IAsyncCursorSource{BsonDocument"/> 异步游标所迭代的到的第一个 <see cref="BsonDocument"/>
        /// 对象,并将该对象反序列化为给定的实体对象类型。
        /// </summary>
        /// <param name="source">包含数据的异步游标。</param>
        /// <typeparam name="TEntity">要转换到的实体对象类型。</typeparam>
        /// <returns>
        /// 给定的异步游标所迭代到的第一个实体对象。如果给定的异步游标无法迭代出任何对象,返回
        /// <code>default(<typeparamref name="TEntity"/>)</code>。
        /// </returns>
        public static async Task <TEntity> FirstEntityOrDefaultAsync <TEntity>(
            this IAsyncCursorSource <BsonDocument> source)
        {
            Contract.NotNull(source, nameof(source));

            var bsonDoc = await source.FirstOrDefaultAsync();

            if (Equals(bsonDoc, default(TEntity)))
            {
                return(default);
Esempio n. 2
0
        public async Task <BsonDocument> ReadVersionAsync(string symbol)
        {
            Log.Debug("reading {symbol} version", symbol);
            IAsyncCursorSource <BsonDocument> versions = this._versions.AsQueryable()
                                                         .Where(x => x ["symbol"] == symbol)
                                                         .OrderByDescending(x => x ["version"])
                                                         .Take(1);
            var rtn = await versions.FirstOrDefaultAsync <BsonDocument>();

            Log.Debug("read {0} version: {1}".Args(symbol, rtn));
            return(rtn);
        }