如果我有亚音速2.2中创建一个DAL,我怎么通过转换可以在代码中创建的WPF ObservableCollections的集合(pref.VB.NET)将通过WPF消耗?
Answer 1:
对不起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);
}
Answer 2:
您必须手动添加到您的DAL类,但它不是太难。 在每一个数据访问层类的顶部,加上“实现INotifyPropertyChanged”,然后在每个属性,在“设置”就像你看到下面的代码添加。
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
文章来源: Create A WPF ObservableCollection From A SubSonic 2.2 Collection