コード例 #1
0
        public async Task SumAsync_Int32_WithSelector()
        {
            EntityMapping.RegisterType(typeof(QueryableAsyncSumModel));

            var connection = TestConfiguration.GetConnection();
            var context    = new MongoDbContext(connection);
            var provider   = new MongoFrameworkQueryProvider <QueryableAsyncSumModel>(connection);
            var queryable  = new MongoFrameworkQueryable <QueryableAsyncSumModel>(provider);

            context.ChangeTracker.SetEntityState(new QueryableAsyncSumModel {
                Title = "SumAsync_Int32_WithSelector.1", Int32Number = 7
            }, EntityEntryState.Added);
            context.ChangeTracker.SetEntityState(new QueryableAsyncSumModel {
                Title = "SumAsync_Int32_WithSelector.2", Int32Number = 5
            }, EntityEntryState.Added);
            context.SaveChanges();

            var result = await queryable.SumAsync(e => e.Int32Number);

            Assert.AreEqual(12, result);
        }