Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AttachAsXXX methods to DbDomainService: #506

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/OpenRiaServices.EntityFramework/Framework/DbDomainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ private static async Task SetChangeSetConflictsAsync(Dictionary<DbEntityEntry, C

// Determine which members are in conflict by comparing original values to the current DB values
var dbValues = await stateEntry.GetDatabaseValuesAsync(cancellationToken);

PropertyDescriptorCollection propDescriptors = TypeDescriptor.GetProperties(operationInConflict.Entity.GetType());

// dbValues will be null if the entity has been deleted in the store (i.e. Delete/Delete conflict)
Expand Down Expand Up @@ -304,5 +304,22 @@ private static async Task SetChangeSetConflictsAsync(Dictionary<DbEntityEntry, C
}
}
}

/// <summary>
/// Mark the entity as modified
/// </summary>
/// <typeparam name="TEntity">Entity type</typeparam>
/// <param name="entity">The modified entity</param>
protected void AttachAsModified<TEntity>(TEntity entity)
where TEntity : class
{
var dbSet = DbContext.Set<TEntity>();
var original = ChangeSet.GetOriginal(entity);

if (original != null)
dbSet.AttachAsModified(entity, original, DbContext);
else
dbSet.AttachAsModified(entity, DbContext);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void AddProduct(Product product)
[Update]
public void UpdateProduct(Product current)
{
this.DbContext.Products.AttachAsModified(current, this.ChangeSet.GetOriginal(current), this.DbContext);
AttachAsModified(current);
}

[Delete]
Expand Down
Loading