New Posts New Posts RSS Feed: Checkbox and Associations
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Checkbox and Associations

 Post Reply Post Reply
Author
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Topic: Checkbox and Associations
    Posted: 29-May-2012 at 11:21am
Removing entities from the EntityManager doesn't delete them. It just removes them from the cache. To delete them you have to call the Delete method on the EntityAspect:
 
a.EntityAspect.Delete() or
 
EntityAspect.Wrap(a).Delete() if you do code-first and don't have the EntityAspect property.
 
Now, keep in mind, the entity is still in the cache at this point, marked for deletion. Once you call SaveChangesAsync, the corresponding record will be deleted from the database and then the entity will get removed from the cache.
 
The typical logic for handling checkboxes is if the user unchecks an item, you call EntityAspect.Delete to mark it for deletion. If the user changes their mind and checks it again, you call EntityAspect.RejectChanges, to undelete the entity.
 
If the user checks a new item that hadn't been checked before, you create a new entity and add it to the EntityManger. Now here comes the tricky part. If the user changes their mind, you call EntityAspect.Delete(). Because you called Delete on an Added entity, the entity isn't marked for deletion, but simply detached from the EntityManager, because the entity doesn't exist in the data source yet. So, now if the user changes their mind again and checks the item again, you can either add the detached entity back to the EntityManager with EntityAspect.AddToManager() or you can create an entire new entity and add it.
 
Hope this helps.


Edited by mgood - 29-May-2012 at 11:37am
Back to Top
pponzano View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Apr-2011
Location: Italy
Posts: 165
Post Options Post Options   Quote pponzano Quote  Post ReplyReply Direct Link To This Post Posted: 29-May-2012 at 8:29am
Hello,
I go a lot of difficulties with Ideablade and a silverlight application I'm developing.... in the specific I've a uploads/1136/Untitled.rar that represent an association between script and variables...

I wish to have a page where the user chooses witch variables is assigned to wich script (I've used a ListBox to represent the variables)

My first problem is :

I've got 20 variables ...how do I show the 20 but when saving/loading just show the items that represents the association SCRIPT_VARIABILI? If I bind my template to SCRIPT_VARIABILI I just see the specific, not all the items...

Second problem :

I've tought of delete all the SCRIPT_VARIABILI during the save and just to add the checked ones but it doesn't work.... can someone provide me a sample on how to do so?
Thanks

The code I used for deleting is

public OperationResult DeleteLinkScriptVariables(SCRIPT script,Action onSuccess = null, Action<Exception> onFail = null)
{
foreach (var a in script.SCRIPT_VARIABILI.ToList())
{
// Manager.RemoveEntity(a);
// a.EntityAspect.RemoveFromManager(true); //no one works...
}

EntitySaveOperation op = Manager.SaveChangesAsync();
return op.OnComplete(onSuccess, onFail).AsOperationResult();
}

Thanks
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down