0

各位程序员,我如何使用实体框架来填充 POCO?换句话说,我已经编写了一个名为 Car 的类,其中包含 3 个属性

Public Class Car
Private _car_id As Int32
Private _car_make As String
Private _car_model As String


Public Sub New(ByVal car_id As Int32, _
               ByVal car_make As String, _
               ByVal car_model As String)
End Sub


Public Property Car_id As Int32
    Get
        Return _car_id
    End Get
    Set(value As Int32)
        _car_id = value
    End Set
End Property

Public Property Car_Make As String
    Get
        Return _Car_Make
    End Get
    Set(value As String)
        _car_make = value
    End Set
End Property

Public Property Car_Model As String
    Get
        Return _car_model
    End Get
    Set(value As String)
        _car_model = value
    End Set
End Property
End Class

现在我需要填充一个 IEnumerable 以保留我的汽车对象列表以供将来使用,并且我需要在我的代码中对另一个实体调用执行交叉比较。

Public Function GetCars() As IEnumerable(Of CarDB)

Dim data As New List(Of CarDB)

Using ctx As New FundingEntities()

    Dim query = From x In ctx.tbl_cars
    Select New ???????????

这就是我迷路的地方......我如何填写我的 IEnumberabl(Of CarDB)????

任何优秀的 POCO 和实体编码员请伸出援手,这样我就可以克服这个困难......

谢谢

4

1 回答 1

0

这可能与 LINQ 更相关。只要 tbl_cars 包含您打算存储在“汽车”对象中的所有三个字段,您就可以执行以下操作:

Dim query As IEnumerable(Of Car) = From x In ctx.tbl_cars Select New Car With {.Car_id = x.Id, .Car_make = x.Make, .Car_Model = x.Model}
于 2013-08-29T18:16:59.653 回答