从 SubSonic 2.2 集合创建 WPF ObservableCollection

发布于 2024-07-19 09:34:39 字数 104 浏览 5 评论 0原文

如果我有一个由 SubSonic 2.2 创建的 DAL,如何将其创建的集合转换为代码 (pref.VB.NET) 中的 WPF ObservableCollections 以供 WPF 使用?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

债姬 2024-07-26 09:34:39

抱歉!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);
}

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);
}
陌伤浅笑 2024-07-26 09:34:39

您必须手动将其添加到您的 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文