public void UpdateFirstCar() { int carId = 4; using (var ts = new TransactionScope()) { using (var uow = new UnitOfWorkScope <CarsContext>(UnitOfWorkScopePurpose.Writing)) { Car c = SharedQueries.GetCar(carId); c.Color = "White"; uow.SaveChanges(); } using (var ctx = new CarsContext()) { Assert.AreEqual("White", ctx.Cars.Single(c => c.CarId == carId).Color); } } using (var ctx = new CarsContext()) { Assert.AreEqual("Red", ctx.Cars.Single(c => c.CarId == carId).Color); } }
private async Task <TCacheableObject> GetOrCreateAsync <TCacheableObject>( string cacheKey, Func <Task <TCacheableObject> > queryCacheableObject, Func <Data.ModelModificationDate, DateTime> getModificationDate) where TCacheableObject : class, ICacheableObject { TCacheableObject cacheableObject; if (this.memoryCache != null) { cacheableObject = this.memoryCache.Get <TCacheableObject>(cacheKey); var databaseModelModificationDate = await SharedQueries.GetModelModificationDateAsync(this.context); var modificationDate = getModificationDate(databaseModelModificationDate); if (cacheableObject != null && modificationDate <= cacheableObject.CacheValuesDateTime) { return(cacheableObject); } cacheableObject = await queryCacheableObject().ConfigureAwait(false); cacheableObject.CacheValuesDateTime = modificationDate; var cacheEntryOptions = new MemoryCacheEntryOptions() .SetPriority(CacheItemPriority.NeverRemove); this.memoryCache.Set(cacheKey, cacheableObject, cacheEntryOptions); return(cacheableObject); } return(await queryCacheableObject()); }
public Repository(IDbConnectionProvider dbConnectionProvider, SharedQueries sharedQueries) { _dbConnectionProvider = dbConnectionProvider; _sharedQueries = sharedQueries; }