Combining Lookup and Operational entities in WPF to bind

Posts   
 
    
Matt831
User
Posts: 3
Joined: 30-Mar-2011
# Posted on: 30-Mar-2011 22:31:34   

LLBLGen 3.1 Final - SQL Server 2008 - Using Visual Studio 2010 - VB.NET - WPF

There may be a simple solution for this, but I have not been able to find it yet. Basically, I am trying to combine entities that may not have specific DB relations and bind them to a WPF multi-select combobox. I would always be using two tables for each scenario and am looking to make this as generic as possible. I would have a Lookup table and and operational table. Due to NDA I cannot post actual object names, but it should be simple enough to describe.

The following SQL statement would accomplish the result I am looking to get:

SELECT t1.IDField AS Id, t1.NameField AS Name, t2.SomeBoolean AS IsChecked FROM LookupTable AS t1 LEFT OUTER JOIN OperationalTable AS t2 ON t1.IDField = t2.IDField

The sample WPF control in my XAML:

<ComboBox Name="cmbMulti" IsEditable="True" SelectedItem="" IsReadOnly="True" ItemsSource="{Binding MyList}" SelectedValuePath="Id"> <ComboBox.ItemTemplate> <HierarchicalDataTemplate> <CheckBox Content="{Binding Name, NotifyOnSourceUpdated=True}" IsChecked="{Binding IsChecked}" Click="CheckBox_Checked" /> </HierarchicalDataTemplate> </ComboBox.ItemTemplate> </ComboBox>

Based on the tables below I would expect my multi-select combobox to initialze showing all four items in the lookup tables as the ItemsSource, and would have the two items in the operational table checked via the IsChecked binding.

LookupTable OperationalTable ID Name ID Name 10 Test1 10 Test1 20 Test2 30 Test3 30 Test3 40 Test4

Out of the box I couldn't find a way to make this happen so I created a class called "MultiList", which looks as follows:

Public Class MultiList Implements INotifyPropertyChanged

PropertyStuffHere

    Public Sub New(ByVal intId As Integer, ByVal strName As String, ByVal blnIsChecked As Boolean)
        Id = intId
        Name = strName
        IsChecked = blnIsChecked
    End Sub

    Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
End Class

End Class

In my main class I have a Public Property called "MyList" implemented as follows:

Public _myList As New List(Of MultiList() Public Property PriorAidL As List(Of MultiList) Get _myList.Add(New MultiList(10, "Test1", True)) _myList.Add(New MultiList(20, "Test2", False)) _myList.Add(New MultiList(30, "Test3", True)) _myList.Add(New MultiList(40, "Test4", False)) Return _myList End Get Set(ByVal value As List(Of MultiList)) _myList = value End Set End Property

The additions to the list are hardcoded for now as a Proof Of Concept, but doing this work when these objects could come from different Lookup and Operationals tables seems unnecessary. Also, if I checked or unchecked an item from the multi-select control I would expect the EntityCollection to be updated so SaveMulti() could be called against the OperationalTable when changes need to be saved.

My issue is this custom class my not even be necessary at all if LLBLGen has something to offer that allows me to bind this solution and properly JOIN, Save Entities in a more manageable format.

Any assistance would be appreciated greatly.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 31-Mar-2011 11:02:01   

Based on the tables below I would expect my multi-select combobox to initialze showing all four items in the lookup tables as the ItemsSource, and would have the two items in the operational table checked via the IsChecked binding.

LookupTable OperationalTable ID Name ID Name 10 Test1 10 Test1 20 Test2 30 Test3 30 Test3 40 Test4

Out of the box I couldn't find a way to make this happen

Let's start at the begining to help us understand things better. When you say out of the box you couldn't find a way to make this happen. Did you mean you failed to fetch the correct data (so we should try to help you to fetch the data the way you need it). Or you have failed to bind it or display it in the format you need?

Matt831
User
Posts: 3
Joined: 30-Mar-2011
# Posted on: 31-Mar-2011 14:02:06   

I am able to retrieve the data for each entity individually, but am unable to combine the entitities to properly bind them in my control. I am new with LLBLGen, so this is easy enough to grab via a SQL statement, but I am unsure about the best way to implement this using LLBL.

Matt831
User
Posts: 3
Joined: 30-Mar-2011
# Posted on: 01-Apr-2011 17:30:37   

Any thoughts?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 02-Apr-2011 05:38:58   

Ok, you you want to access fields on related entities. You can do that just adding custom properties (in a partial class) at the main entity. For instance:

public partial class T1Entity
{
     public bool? IsChecked
     {
          get
          {
                bool? toReturn = null;
                // ensure the related entity is fetched and not null
                if (this.T2 != null)
               {
                     toReturn = this.T2.IsChecked;
               }

               return toRerutn;
          }
     }
}

Now T1Entity has a IsChecked property you can use in your databinding. You can do the same if you just add a Related Field on Related Entities, in LLBLGen Designer.

David Elizondo | LLBLGen Support Team