如果我有一个由SubSonic 2.2创建的DAL,我如何将它创建的集合转换为代码(pref.VB.NET)中的WPF ObservableCollections以供WPF使用?
答案 0 :(得分: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);
}
答案 1 :(得分: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