public void ReadMixedEntities()
        {
            var connection = TestConfiguration.GetConnection();
            var context    = new MongoDbContext(connection);
            var provider   = new MongoFrameworkQueryProvider <MixedReadA>(connection);
            var queryable  = new MongoFrameworkQueryable <MixedReadA>(provider);

            context.ChangeTracker.SetEntityState(new MixedReadA
            {
                Description = "MongoFrameworkQueryableTests.ReadMixedEntities"
            }, EntityEntryState.Added);

            context.ChangeTracker.SetEntityState <MixedReadA>(new MixedReadB
            {
                BIsForBoolean = true,
                Description   = "MongoFrameworkQueryableTests.ReadMixedEntities"
            }, EntityEntryState.Added);

            context.SaveChanges();

            var readMixedEntitiesQuery = queryable.Where(e => e.Description == "MongoFrameworkQueryableTests.ReadMixedEntities");

            Assert.AreEqual(2, readMixedEntitiesQuery.Count());
            Assert.AreEqual(2, readMixedEntitiesQuery.OfType <MixedReadA>().Count());
            Assert.AreEqual(1, readMixedEntitiesQuery.OfType <MixedReadB>().Count());
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public async ValueTask <CacheEntry <T>?> GetAsync <T>(string cacheKey)
        {
            await TryConfigureIndexes();

            var provider  = new MongoFrameworkQueryProvider <DbCachedEntry>(Connection);
            var queryable = new MongoFrameworkQueryable <DbCachedEntry>(provider);

            var dbEntry    = queryable.Where(e => e.CacheKey == cacheKey).FirstOrDefault();
            var cacheEntry = default(CacheEntry <T>);

            if (dbEntry != default)
            {
                cacheEntry = new CacheEntry <T>((T)dbEntry.Value !, dbEntry.Expiry);
            }

            return(cacheEntry);
        }