Search code examples
vb.netlightswitch-2013

Unable Save a record to Lightswitch.ApplicationData with relationship to seperate database


Setup: 2 databases Lightswitch.applicationdata with table Customers SQL.PlaceNamesData with tables Countries, States, Places and PostCodes AddCustomer screen is a New Data Screen. This screen has 3 autocomplete boxes to filter country, state, place. Postcode is a one to one relationship with place.

Issue: In the code provided I am trying to save the fields to the new customer record, however the selected country, state, place and postcode are not being saved with the companyname and other details. Instead each of the foreign keys from the PlaceNamesData DB are saving in ascending order based on the postcodenum field.

I have been trying different methods for a few days now. How do I save the filtered screen values to the foreign keys in the Customer record?

Namespace LightSwitchApplication

    Public Class AddCustomer

        Private Sub AddCustomer_InitializeDataWorkspace(saveChangesTo As List(Of Microsoft.LightSwitch.IDataService))
            ' Write your code here.
            Me.CustomerProperty = New Customer()
        End Sub

        Private Sub AddCustomer_Saved()
            ' Write your code here.
            Me.Close(False)
            Application.Current.ShowDefaultScreen(Me.CustomerProperty)

        End Sub

        Private Sub SaveCustomer_Execute()
            Dim newCustomer As Customer = Me.CustomerProperty
            Dim co As Country = Me.CountryProp.Country
            Dim st As State = Me.StateProp.State
            Dim pl As Place = Me.PlaceProp.Place
            Dim po As PostCode = Me.PlaceProp.PostCode      
            With newCustomer
                .CompanyName = Me.CustomerProperty.CompanyName
                .Street = Me.CustomerProperty.Street
                .AccountTerms = Me.CustomerProperty.AccountTerms
                .TaxRate = Me.CustomerProperty.TaxRate
                .Country = co
                .State = st
                .Place = pl
                .PostCode = po
            End With
        End Sub

        Private Sub AddCustomer_Saving(ByRef handled As Boolean)
            ' Write your code here.
            handled = True
        End Sub
    End Class

End Namespace


Solution

  • Ahhhhg fixed - Incorrect relationships setup between intrinsic DB and external DB.