React to EF changes

This commit is contained in:
ajcvickers 2015-01-30 15:13:49 -08:00
parent 5b55da271c
commit 61ef19c6e9
6 changed files with 10 additions and 11 deletions

View File

@ -86,9 +86,9 @@ namespace MusicStore.Models
{ {
foreach (var item in entities) foreach (var item in entities)
{ {
db.Entry(item).SetState(existingData.Any(g => propertyToMatch(g).Equals(propertyToMatch(item))) db.Entry(item).State = existingData.Any(g => propertyToMatch(g).Equals(propertyToMatch(item)))
? EntityState.Modified ? EntityState.Modified
: EntityState.Added); : EntityState.Added;
} }
await db.SaveChangesAsync(); await db.SaveChangesAsync();

View File

@ -55,7 +55,7 @@ namespace MusicStore.Models
cartItem.Count++; cartItem.Count++;
// TODO [EF] Remove this line once change detection is available // TODO [EF] Remove this line once change detection is available
_db.Entry(cartItem).SetState(EntityState.Modified); _db.Update(cartItem);
} }
} }
@ -75,7 +75,7 @@ namespace MusicStore.Models
cartItem.Count--; cartItem.Count--;
// TODO [EF] Remove this line once change detection is available // TODO [EF] Remove this line once change detection is available
_db.Entry(cartItem).SetState(EntityState.Modified); _db.Update(cartItem);
itemCount = cartItem.Count; itemCount = cartItem.Count;
} }
@ -94,8 +94,7 @@ namespace MusicStore.Models
foreach (var cartItem in cartItems) foreach (var cartItem in cartItems)
{ {
// TODO [EF] Change to DbSet.Remove once querying attaches instances _db.Remove(cartItem);
_db.Entry(cartItem).SetState(EntityState.Deleted);
} }
} }

View File

@ -134,7 +134,7 @@ namespace MusicStore.Areas.Admin.Controllers
{ {
if (ModelState.IsValid) if (ModelState.IsValid)
{ {
_dbContext.Entry(album).SetState(EntityState.Modified); _dbContext.Update(album);
await _dbContext.SaveChangesAsync(Context.RequestAborted); await _dbContext.SaveChangesAsync(Context.RequestAborted);
//Invalidate the cache entry as it is modified //Invalidate the cache entry as it is modified
_cache.Remove(GetCacheKey(album.AlbumId)); _cache.Remove(GetCacheKey(album.AlbumId));

View File

@ -70,9 +70,9 @@ namespace MusicStore.Models
{ {
foreach (var item in entities) foreach (var item in entities)
{ {
db.Entry(item).SetState(existingData.Any(g => propertyToMatch(g).Equals(propertyToMatch(item))) db.Entry(item).State = existingData.Any(g => propertyToMatch(g).Equals(propertyToMatch(item)))
? EntityState.Modified ? EntityState.Modified
: EntityState.Added); : EntityState.Added;
} }
await db.SaveChangesAsync(); await db.SaveChangesAsync();

View File

@ -56,7 +56,7 @@ namespace MvcMusicStore.Controllers
{ {
if (ModelState.IsValid) if (ModelState.IsValid)
{ {
_storeContext.Entry(album).SetState(EntityState.Modified); _storeContext.Update(album);
await _storeContext.SaveChangesAsync(); await _storeContext.SaveChangesAsync();

View File

@ -73,7 +73,7 @@ namespace MvcMusicStore.Controllers
{ {
if (ModelState.IsValid) if (ModelState.IsValid)
{ {
_storeContext.Entry(album).SetState(EntityState.Modified); _storeContext.Update(album);
await _storeContext.SaveChangesAsync(); await _storeContext.SaveChangesAsync();