Problem : LS allows a master record to be deleted (in screen) even though the entity has few children exist with “Restricted” relationship between them. But it generates the validation error when we try to save the entity and there is no way to get rid of them (by design).
Summery : In LS “Beta2″ days, I posted a bug and acknowledged by LS Team. Now I created a project to see if this bug was cleared. It actually did (now LS assigns “1″ as a starting number of ID entities), but found another issue with it. And I’m not sure, whether this one was pre-exist in Beta2 or not.
On Screen Level, even if my entities’ relationship has ‘Restricted’ deletion, LS actually allows to delete the Master record when there are child records exist and it catch this when the records are trying to post back to DB with SAVE method.
If we try to delete an “existing Master record”, at least now we have a choice to go back and delete the child records one-by-one on the screen, as LS put a “X” icon next to the master record, but at least it still exist in the screen.
But if we delete a newly added master record with children (that are not exist in DB), now LS clears the master/child records from the SCREEN and there is no way to get rid of its validation errors, when we try to SAVE the screen.
You can see these series of screen shot of what I mean.
Workaround : Right now, all what I did was restrict Master’s deletion method by overriding its code with below. What I expect from LS is that, it should capture this ‘Restricted’ association on the screen and should prevent deletion.
[sourcecode language="csharp"]
partial void TempProductListDeleteSelected_CanExecute(ref bool result)
{
if (TempProducts.SelectedItem == null)
return;
if (TempProducts.SelectedItem.TempOrderDetails.Count() > 0)
result = false;
else
result = true;
}
[/sourcecode]
Discussion Threads
Super and thnks Boss!