Save pipeline works, but nothing to show for it in SQL Server RRS feed

  • Question

  • I'm using VS Lightswitch 2013, with Update 3 I believe.  I've recently come across a problem whereby if I go to an HTML Edit screen and add an entity, the new entity never shows up in SQL Server.

    I've set breakpoints on the _Inserting and _Inserted methods, as well as the SaveChanged_Executed method.  Each one of them is hit when I save, and I can see a new Id value in my entity (along with the other new values of the entity) when I inspect it in the _Inserted method-- in fact, that ID increments each time I try to save an entity, which tells me SQL Server is doing *something* each time I add.

    No exceptions appear to be thrown, and the SaveChanges_ExecuteFailed method is never hit on a breakpoint.  Editing existing records works fine, it's inserting that the issue comes up.

    How can I start to debug something like this, and has anyone ever seen it before?

    Monday, March 7, 2016 6:47 AM


All replies

  • Did you check if you can see the new records in sql server management studio?  Sometimes records will be added to the database but not show up in LightSwitch.  That is an issue that can be address by looking at the msls.MergeOption.  If the records are not being added to the database at all, and no errors bubble up, that is very strange.
    Monday, March 7, 2016 3:00 PM
  • Hi Hessc,

    Thanks for your reply.  I did check SQL Server directly, using the server explorer in VS 2013, and no records appeared. 

    However, I did get things to work finally, by noodling with the most-recently added field to the table.

    In this case, it's a boolean called 'IsDeleted', that I'm adding to various tables, so that I can 'soft-delete' records, rather than have to actually remove them.

    In this case, 'IsDeleted' was marked as required in the table's LS design window.  That was causing trouble whenever I added a record -- I would get an error saying 'IsDeleted is required'-- so I marked it as not required in the LS designer.  That's when the trouble I listed above started.

    On a longshot, I went into my entity's _Inserting method and added the line 'entity.IsDeleted = false' in there.  That did the trick, and new records are now being inserted into SQL Server.

    However, I got lucky in that I found a workaround.  My main question still remains; namely, is there a way to debug the sort of problem I saw originally?  Also, would anyone guess why I had to put the code I did in my _Inserted method for this to actually insert the row into SQL Server?

    Monday, March 7, 2016 3:42 PM
  • It was a validation error so it was preventing the save.  Filling in the required value in the _inserting method is one way around it.  You could have also used the _created method, beforeApplyChanges method, AllowSaveWithErrors -- anything that would fill in the value would work.  Normally that error should have bubbled up to the client.  I wonder if you needed to do a clean and rebuild all after removing the isRequired property.  Perhaps, that could have broke something in the .lsml. 
    Monday, March 7, 2016 7:45 PM
  • I agree that a Clean then a Rebuild (then open a screen designer so the .lsml files will update) should have fixed the problem... by resetting IsDeleted to being required again :)

    However, while the Client may swallow server side errors, the OData call (that would show up in Fidder) should not be swallowed unless there was a Try/Catch manually placed somewhere that was swallowing it).

    Unleash the Power - Get the LightSwitch HTML Client / SharePoint book


    • Marked as answer by jim bancroft Thursday, March 10, 2016 5:39 PM
    Monday, March 7, 2016 10:32 PM