1

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?

4

2 回答 2

0

对不起!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);
}
于 2009-05-18T16:03:07.960 回答
0

您必须手动将其添加到您的 DAL 类中,但这并不难。在每个数据访问层类的顶部,添加“Implements INotifyPropertyChanged”,然后在每个属性中,添加“set”中的代码,如下所示。

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
于 2009-05-29T06:45:59.627 回答