tags:

views:

247

answers:

2

If I have a DAL created by SubSonic 2.2, how do I convert the Collections created by it to WPF ObservableCollections in code (pref.VB.NET) to be consumed by WPF?

TIA, Kevin

A: 

Sorry !VB:

[Test]
public void Exec_Testing()
{
    ProductCollection products =
        DB.Select().From("Products")
            .Where("categoryID").IsEqualTo(5)
            .And("productid").IsGreaterThan(50)
            .ExecuteAsCollection<ProductCollection>();

    Assert.IsTrue(products.Count == 77);

    ObservableCollection<Product> obsProducts = new ObservableCollection<Product>(products);
}
P a u l
Thank you. I used the DeveloperFusion.com converter to give me:Dim obsProducts As New ObservableCollection(Of Product)(products)
Yes, this works, however the classes don't inherit INotifyPropertyChanged, so... The will bind, but will not report property changes.
Rick Ratayczak
How do I solve that? (sorry, I am a .NET newbie)
INotifyPropertyChanged was implemented in subsonic 3. I retrofitted this into v2. See http://code.google.com/p/subsonicproject/issues/detail?id=90 for an example of how to modify the class template -- you will have to read the patch file. I don't use VB so you would have to roll your own edits into the VB class template. It's really very easy.
P a u l
A: 

You would have to manually add this to your DAL classes, but it's not too hard. In the top of each data access layer class, add "Implements INotifyPropertyChanged" and then in each property, add the code in the "set" like you see below.

Private _Book As String
Public Property Book() As String
    Get
        Return _Book
    End Get
    Set(ByVal value As String)
        If Not _Book = value Then
            _Book = value
            ' Raise the property changed event.
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("Book"))
        End If
    End Set
End Property 

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