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 に答える