Print Page | Close Window

When deleting an entity have to call the repository twice?

Printed From: IdeaBlade
Category: Cocktail
Forum Name: Community Forum
Forum Discription: A professional application framework using Caliburn.Micro and DevForce
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3691
Printed Date: 26-Apr-2024 at 6:21am


Topic: When deleting an entity have to call the repository twice?
Posted By: pponzano
Subject: When deleting an entity have to call the repository twice?
Date Posted: 03-Oct-2012 at 9:37am
Hello,
suppose I've got an entity VARIABLES and I delete it doing
 
OperationResult DeleteVariables(VARIABLES v)
{
v.EntityAspect.Delete();
 
return AlwaysCompletedOperationResult.Instance
 
then at the Operation.CompletedSuccessfully call :
 
public OperationResult SaveAsync(Action onSuccess = null, Action<Exception> onFail = null)
     {
         EntitySaveOperation op = entityManagerProvider.Manager.SaveChangesAsync();
         return op.OnComplete(onSuccess, onFail).AsOperationResult();
     }
 
Or there's a simpler way in SL?
Thanks



Replies:
Posted By: smi-mark
Date Posted: 03-Oct-2012 at 10:28am
You have to delete and save, because until you save, it is only deleted in memory.

However, when you switch to DF2012 and VS 2012, the syntax is much easier

you can simply do something like:

public async void Delete()
{
   myEntity.Delete();
   await SaveAsync();
}

public async Task SaveAsync()
{
            return entityManagerProvider.Manager.SaveChangesAsync();
}



Print Page | Close Window