none
LIGHTSWITCH SILVERLIGHT Master Detail in Row Details RRS feed

  • Question

  • Hello,

    perhaps, anybody can help me.

    Since 10 Days, i try to create a Lightswitch application with master details. Very simple. Customers with relationship to orders.

    In Lightswitch itself, i have no Problem.

    But i´ll use third Party controls like Silverlight Grids, Telerik or componentone to enhenace the UI.

    I´ll Show the details in a row-detail grid like in the sample of telerik (ordders)

    Telerik Grid View - First Look Demo

    But it seems, if i bind the grid to Screen.customers the Business object does´nt contains the Ordercollection.

    With Pauls great post

    Eager loading related entities in LightSwitch 2012 in a custom control

    i get now the customers and orders. But i have extend the query in Lightswitch to make complex queries before displaying the datas. And this does´nt work in this Scenario.

    All what i want is to Display the customers with silverlight or third-party grid and diaply also the related orders in a row Detail.

    Hope anybody can help me instead of my bad english :-(

    Regards

    Thomas


    Thomas Bach


    Friday, January 18, 2013 5:58 PM

Answers

All replies

  • I think, i´ve found the solution.

    LightSwitch TreeView Custom Control

    Thanks Karol.

    Regards

    Thomas


    Thomas Bach


    Sunday, January 20, 2013 2:00 PM

  • With Pauls great post

    Eager loading related entities in LightSwitch 2012 in a custom control

    i get now the customers and orders. But i have extend the query in Lightswitch to make complex queries before displaying the datas. And this does´nt work in this Scenario.


    Thank you for referencing my article.

    What the eager loading approach can do is querying in one request a series of customers with all their related orders. Obviously, you can restrict (by means of a where clause) on the customers (e.g. only the customers in France), but what's not possible is to restrict on the returned orders. (e.g. only the related orders for product 'Surface tablet') All orders will be returned or no orders (if you disable eager loading).  Would be great to learn if someone has a solution for this.


    paul van bladel

    Tuesday, January 22, 2013 7:14 AM
  • Hi Paul,

    i think, i´ve found a way to solve my problem. May be, it´s a wrong way and i have not enough knowledge in coding, Silverlight and Lightswitch.

    But perhaps, it´s a base for discussion.

    Problem:

    To enhace the UI of Lightswitch, i like Display customers and related orders in a silverlight grid. In my case, with telerik controls.

    The orders should displayed in a rwo-detail of the customer line.

    It´s not a problem to bind the customer to the main-grid.

    <telerik:RadGridView  x:Name="AdressenGrid" 
                                  ItemsSource ="{Binding Screen.Q_AdresseNachMatchCode, Mode=TwoWay}" 
                                  SelectedItem="{Binding Screen.Q_AdresseNachMatchCode.SelectedItem, Mode=TwoWay}" 
                                  AutoGenerateColumns="False" 
                                  ColumnWidth="*" 
                                  RowDetailsVisibilityMode="Collapsed" 
                                  Grid.Row="0">
    
    
    

    But i haven´t found any solution to bind the related orders in a row Detail.

    In case og binding syntax, either the returned values are empty or a Targetexception is fired.

    Telerik gave´s up, but the problem exists also with a sdk-Silverlight-Grid.

    After Long time of searching, i´ver found Karol Zadoras Article (Thanks Karol)

    http://social.msdn.microsoft.com/Forums/en-US/lsextensibility/thread/bcdaa86f-459a-47d3-853a-3c5e56eb088a/

    If i understand right, the problem is the threading model.

    Like in this Article, i created a converter class.

    Public Class EntityCollectionValueConverter
        Implements IValueConverter
    
        Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
            Dim entity As IEntityObject = TryCast(value, IEntityObject)
    
            If entity Is Nothing Then
                Throw New ArgumentException("The converter should be using an entity object")
            End If
    
    
            Dim sourcePropertyName As String = TryCast(parameter, String)
    
            If String.IsNullOrWhiteSpace(sourcePropertyName) Then
                Throw New ArgumentException("Converter parameter should be set to the property name that will serve as source of data")
            End If
    
            ' Enumerate the source property using logic dispatcher 
    
            ' and prepare the collection of entities that the control will bind to
    
            Dim entities = New ObservableCollection(Of IEntityObject)()
    
            Dim temporaryEntites = New List(Of IEntityObject)()
    
            entity.Details.Dispatcher.BeginInvoke(Sub()
                                                      Dim eCollection As IEntityCollection = TryCast(entity.Details.Properties(sourcePropertyName).Value, IEntityCollection)
    
                                                      If eCollection Is Nothing Then
                                                          System.Diagnostics.Debug.Assert(False, "The property " & sourcePropertyName & " is not an entity collection")
                                                          Return
                                                      End If
    
                                                      ' Now we are on the logic thread. We cannot just stuff the observable collection 
    
                                                      ' with entities because the collection will immediately raise Changed events 
    
                                                      ' and this will result in invalid cross-thread access. So we'll use a temporary collection
    
                                                      ' and copy the entites again on the UI thread
    
                                                      For Each e As IEntityObject In eCollection
                                                          temporaryEntites.Add(e)
                                                      Next
    
    
                                                      ' I wish ObservableCollection had an AddRange() method...
    
                                                      Microsoft.LightSwitch.Threading.Dispatchers.Main.BeginInvoke(Sub()
                                                                                                                       For Each e As IEntityObject In temporaryEntites
                                                                                                                           entities.Add(e)
                                                                                                                       Next
    
                                                                                                                   End Sub)
    
                                                  End Sub)
    
    
    
            Return entities
    
        End Function
    
    
        Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
            Throw New NotImplementedException()
        End Function
    
    
    End Class
    

    With this class, i can bind the orders (in my case BelegeItem) to the grid-Datasource in a row detail.

     <telerik:RadGridView x:Name="BelegeGrid" 
                                             
        ItemsSource="{Binding Converter={StaticResource EntityCollectionValueConverter},ConverterParameter=BelegeItem}"
        AutoGenerateColumns="False" 
        ColumnWidth="*" 

    This works for me. The right orders are displayd in the row-detail.

    But at this time, i have also two additional proplems:

    1.) As you wrote, it´s not possible to filter the orders about any field.

    As a Workaround, i´m using the telerik filters. In conclusion with Teleriks RadDataPager, the Performance is good enough for my application. But it would better, if i could use a filter or parameterd Query direct from Lioghtswitch.

    2.) My orders (not the customers) has another relation to positions. An now, i like Display the positions of an order, selected in row-detail, in another grid-cell of row-details.

    At this Point, the valueconverter fires an exception if i use a line like this:

    ItemsSource="{Binding Converter={StaticResource EntityCollectionValueConverter},ConverterParameter=Beleg_Positionen}"

    (Beleg-Positionen(positions) is relatet to the Beleg-Item(order) is related to  Q_AdresseNachMatchCode(customers)

    Regards

    Thomas


    Thomas Bach

    Tuesday, January 22, 2013 9:33 AM