I'm working with open acces orm and I need a simple way to fetch just parent entity information and make a custom load of related children information. I mean when I ask for order I just want the orders information and to be able to load or not the orderlines information.
If I have:
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
What can I do if I want for example:
Dim e as new EntitiesModel()
Dim q as Order = (from c in e.Orders
where c.Number = 5
select c).FirstOrDefault()
And I need that the query just to retrieve Order Data and not OrderLines, which seems what OA do by default.
Edit: I've already tried this:
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
I'm still receiving OrderLines data and I don't need that data always.Most of telerik's examples are about to load related data, but I want the opposite. Is there a way to specify wether I want or not to do it? I hope to be clear :/
You need to declare that the "OrderLines" should be lazy loaded. You could use the FetchPlans API or declare the association to be loaded lazily explicitly in the configuration.
If you using code-only mapping you can define the load behavior:
orderLineConfiguration.HasAssociation(x => x.Order).WithLoadBehavior(Telerik.OpenAccess.LoadBehavior.Lazy).WithOpposite(c => c.OrderLines);
The OrderLines will now be lazy loaded. Please refer to the documentation here and here.