-2

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 :/

  • welcome at SO! We expect that a user has done a lot of "try and error" before asking a question here. Please show us what you've done and why that didn't work for you. – Wouter J Mar 15 '13 at 22:38

1 Answers1

0

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.

cubski
  • 3,218
  • 1
  • 31
  • 33
  • Thanks, I had some problems understanding what lazy loading and the way open access worked with was... But with links you provided I got it =) – user1824644 Mar 19 '13 at 21:31
  • Glad I could help. I suggest also looking into the documentation further as well as the sample pack as there are a lot of very useful APIs in OpenAccess. – cubski Mar 20 '13 at 13:41