Print Page | Close Window

Checkbox and Associations

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3462
Printed Date: 02-May-2025 at 3:14pm


Topic: Checkbox and Associations
Posted By: pponzano
Subject: Checkbox and Associations
Date 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 - 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



Replies:
Posted By: mgood
Date 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.



Print Page | Close Window