Reacting to EF API changes

This commit is contained in:
ajcvickers 2014-12-08 15:21:24 -08:00
parent 6120168c86
commit 9b72e3a0bd
6 changed files with 10 additions and 10 deletions

View File

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

View File

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

View File

@ -138,7 +138,7 @@ namespace MusicStore.Areas.Admin.Controllers
{
if (ModelState.IsValid)
{
db.Entry(album).State = EntityState.Modified;
db.Entry(album).SetState(EntityState.Modified);
await db.SaveChangesAsync(Context.RequestAborted);
//Invalidate the cache entry as it is modified
cache.Remove(string.Format("album_{0}", album.AlbumId));

View File

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

View File

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

View File

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