我正在尝试将包含一些集合的实体转换为Model
但我不知道如何在模型中包含这些集合。
只是一个简单的例子,请看下面的模型:
Namespace Models
Public Class ProductModel
Public Property ID As Integer
Public Property Description As String
Public Property IsInStock as Boolean
Public Property Orders As List(Of ProductOrderModel)
End Class
Public Class ProductOrderModel
Public Property ID As Integer
Public Property OrderDate As DateTime
Public Property DeliveredDate As DateTime?
Public Property ShippingAddress As String
End Class
End Namespace
现在我可以轻松地转换为如下所示的产品模型:
Dim simplifiedProductModel as ProductModel =
From p in dc.Products _
Select New ProductModel With { _
.ID = p.ProductID, _
.Description = p.ProductDescription, _
.IsInStock = p.ProductIsInStock, _
.OrderCount = p.Orders.Count() _
}
我想不通的是如何使用其简化模型来包含该集合。
Dim simplifiedProductModel as ProductModel =
From p in dc.Products _
Select New ProductModel With { _
.ID = p.ProductID, _
.Description = p.ProductDescription, _
.IsInStock = p.ProductIsInStock, _
.OrderCount = p.Orders.Count(), _
.Orders = p.orders.???? ===> New ProductOrderModel
With {
.ID = ???? o.OrderID ,
.OrderDate = ???? o.Createdate,
etc.
}