Answered Bug (?) in Master-Detail deletion

  • Friday, September 02, 2011 3:37 AM
     
     

    I'm unclear that this is a bug or not, but just posted in Connect.  Below is the detail that I posted over there.

    =======================

    In LS Beta 2 days, I had posted a bug and acknowledged by LS Team (http://social.msdn.microsoft.com/Forums/en-US/lightswitchgeneral/thread/081099b2-4365-4a30-8914-68a6566e7600). Now I tried to see if this bug was cleared. It actually did, but found another issue with it.

    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 a "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 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 record from the SCREEN and there is no way to get rid of its validation errors, when we try to SAVE the screen.

     

    How to reproduce :

    ============

    1. Add "Product 1"

    2. Add few "Order Details"  (Order Details & Product has "Restriced" deletion Master-Detail relationship) 

    3. Save

    4. Delete "Product 1" (LS allows to delete the Master, when there are children exist - at least in screen)

    5. SAVE (Throws validation error. You have a choice to delete each children and go further)

    6. Add "Product 2"

    7. Add few "Order Details"

    8. Delete "Product 2" (LS allows to delete, and this time it clears "Product 2" from screen)

    9. SAVE (Throws validation error for children. But there is no way to fix these errors as there is no "Product 2" on the screen)

     

    ====================================================================================================

     

    So, what I understand from the above is, either

     LS is actually capturing its 'validation errors' from SQL SERVER or

     LS is NOT capturing Entity's relationship in screen level on 'deletion'.

     

    Am I make any sense here? 

     


    -Bala
    • Edited by PowerBala Friday, September 02, 2011 3:39 AM fixing link
    •  

All Replies

  • Friday, September 02, 2011 5:09 AM
     
     Answered Has Code

    I can't think of anything else other than manually overwrite the Parent's Delete button's validation.  But to me it beats the purpose of 'Restricted' association and it should do this check before Parent's deletion.

     

            partial void ProductsListDeleteSelected_CanExecute(ref bool result)
            {
                // Write your code here.
     
                if (Products.SelectedItem == null)
                    return;
     
                if (Products.SelectedItem.OrderDetails.Count() > 0)
                    result = false;
                else
                    result = true;
     
            }
    


    -Bala
    • Marked As Answer by PowerBala Saturday, September 03, 2011 9:13 AM
    •