我正在使用开放访问 orm,我需要一种简单的方法来获取父实体信息并自定义加载相关子信息。我的意思是当我要求订单时,我只想要订单信息并且能够加载或不加载订单信息。
如果我有:
Public Class Order
Public Property Number As Long
Public Property Description As String
Public Property OrderLines as List(of OrderLines) = new List(of OrderLines)
End Class
如果我愿意,我该怎么办,例如:
Dim e as new EntitiesModel()
Dim q as Order = (from c in e.Orders
where c.Number = 5
select c).FirstOrDefault()
而且我需要该查询只是为了检索订单数据而不是 OrderLines,这似乎是 OA 默认执行的操作。
编辑:我已经尝试过这个:
Using dbcontext As New EntitiesModel()
Dim fetchStrategy As New FetchStrategy()
dbcontext.FetchStrategy = fetchStrategy
Dim q As Order
q = (From c In dbcontext.Orders
Where c.PK_Order = 79
Select c).FirstOrDefault
For Each olFound In q.OrderLines
Dim i As Integer
Console.WriteLN(olFound.Description&VbNewLine)
Next
End Using
我仍在接收 OrderLines 数据,我并不总是需要该数据。telerik 的大多数示例都将加载相关数据,但我想要相反。有没有办法指定我是否想要这样做?我希望清楚:/