0

我正在尝试使用产品类实体、抽象存储库和带有示例数据的假存储库来创建域模型。

我创建了以下产品类

Namespace Entities
Public Class Product
    Dim _ProductID As Integer
    Dim _Name As String
    Dim _Description As String
    Dim _Price As Decimal
    Dim _Category As String
    Public Property ProductID() As Integer
        Get
            Return _ProductID
        End Get
        Set(ByVal value As Integer)
            _ProductID = value
        End Set
    End Property

    Public Property Name() As String
        Get
            Return _Name
        End Get
        Set(ByVal value As String)
            _Name = value
        End Set
    End Property

    Public Property Description() As String
        Get
            Return _Description
        End Get
        Set(ByVal value As String)
            _Description = value
        End Set
    End Property

    Public Property Price() As Decimal
        Get
            Return _Price
        End Get
        Set(ByVal value As Decimal)
            _Price = value
        End Set
    End Property

    Public Property Category() As String
        Get
            Return _Category
        End Get
        Set(ByVal value As String)
            _Category = value
        End Set
    End Property
End Class
End Namespace

以及如下界面:

Namespace Abstract
Public Interface IProductsRepository
    ReadOnly Property Products() As IQueryable(Of Product)
End Interface
End Namespace

我现在需要使用通用 LINQ 列表创建数据,但是我被卡住了,这是我目前所拥有的,但我无法添加项目:

Imports DomainModel.Abstract
Imports DomainModel.Entities

Namespace Concrete
Public Class FakeProductsRepository
    Implements IProductsRepository
    Private Shared fakeProducts As IQueryable(Of Product) = New List(Of Product)().AsQueryable

    Public ReadOnly Property Products() As System.Linq.IQueryable(Of Entities.Product) Implements Abstract.IProductsRepository.Products
        Get
            Return fakeProducts
        End Get
    End Property

End Class
End Namespace

样品项目:

fakeProducts.Add(New Product() With {.Name = "Football", .Price = 25})

非常感谢帮助..

4

1 回答 1

0

我现在需要使用通用 LINQ 列表创建数据,但是我被卡住了,这是我目前所拥有的,但我无法添加项目:

“创建数据”是什么意思?此外,LINQ 用于检索数据,而不是相反。您可以简单地将数据放入一个列表并返回该列表——它可查询的:

Private ReadOnly fakeProducs As New List(Of Product)
...

fakeProducts.Add(New Product() With {.Name = "Football", .Price = 25})

...

Public ReadOnly Property Products() As System.Linq.IQueryable(Of Entities.Product) Implements Abstract.IProductsRepository.Products
    Get
        Return fakeProducts.AsQueryable()
    End Get
End Property
于 2009-10-13T12:08:00.387 回答