Using LLBLGenPro v2.6
I am running into odd issues when I delete an entity from collection, then try to re-sort the collection. In the re-sort, it thinks the collection still contains the entity in question. I am using Ajax, which I don't imagine should be a problem but thought it worth mentioning.
Anyway, here's my code:
- Delete the Section and the Fields under it:
protected void hlRemoveSection_Click(object sender, EventArgs e)
{
LinkButton myButton = (LinkButton)sender;
StageSectionEntity mySection = new StageSectionEntity(Convert.ToInt32(myButton.CommandArgument));
FormStageEntity myFormStage = mySection.FormStage;
Session["MasterPageMessage"] = "Section " + mySection.FormSectionTitle + " deleted.";
mySection.StageSectionField.DeleteMulti();
mySection.Delete();
myFormStage.ReSortSections();
rgGrid.Rebind();
}
- ReSortSections Method in parent Entity User code region:
public void ReSortSections()
{
StageSectionCollection myStageSections = StageSectionCollection.GetSortedSectionsByFormStage(this.FormStageId);
int i = 0;
foreach (StageSectionEntity mySection in this.StageSection)
{
i++;
mySection.SortOrder = i;
mySection.Save();
}
}
- GetSortedSectionsByFormStage:
public static StageSectionCollection GetSortedSectionsByFormStage(int FormStageID)
{
StageSectionCollection mySections = new StageSectionCollection();
IPredicateExpression filter = new PredicateExpression();
filter.Add(StageSectionFields.FormStageId == FormStageID);
SortExpression sorter = new SortExpression();
sorter.Add(StageSectionFields.SortOrder | SortOperator.Ascending);
mySections.GetMulti(filter, 0, sorter, null);
return mySections;
}
For some reason, the GetSortedSectionsByFormStage method is returning all records, including the one that was deleted.
Thanks for any help you can provide.
Laurie