Need help adding child record to read only (sql view) parent RRS feed

  • Question

  • Hi there,

    I have an interesting scenario that's got me stuck and I'm hoping someone has an idea.

    I'm using Visual Studio Premium 2013 to build a Desktop Lightswitch Application.

    I have a search screen based on a sql view (which is, of course, read only). I have a zero to one relationship with a second table that I want to add records to (one record, max). So, each record in the parent view has either zero or one child records associated with it.

    The problem is, I can't figure out how to add the record to the second table. I've explored a few potential solutions, but all failed. I tried adding a second query to the model. I tried various ways of adding a new child to the parent, but the parent is read only and errors on save. I even tried to add empty children automatically on the query server side (but failed to figure out how to do so) so that there would always be a child, even if there isn't on in the database.

    I realize now I'm fighting with the framework, so there's something fundamental I'm missing. So, how to add a new child record to a parent recordset that is based on a read only view? Is that the right question, even?

    I tried to keep this question very simple, so I hope I haven't left anything important out.

    So, there must be a best practice here -- I would really appreciate any help!


    • Edited by Skeeve69 Monday, January 27, 2014 12:56 AM
    Sunday, January 26, 2014 3:21 AM

All replies

  • Hello Skeeve69,

    Can you describe how you defined the relationship between the view and table.  Which side is the primary?  What properties is the relationship defined on?


    Wednesday, February 5, 2014 5:52 PM
  • Instead of adding the child to the selected view item, use the view item's data to retrieve the actual editable parent entity. Then add the child item to that entity.


    Thursday, February 6, 2014 1:35 PM
  • Paul,

    That sounds right. I will try it and write back, but it might be a couple of days. I appreciate the suggestion!

    Michael, the view is the primary. The primary is the one and the secondary table is the zero to one. The key that the relationship is defined on is an integer on the view that exists as an FK in the secondary (zero to one) table.


    Thursday, February 6, 2014 4:16 PM