Page 1 of 1

How to question

Posted: Fri 21 Aug 2009 08:55
by Zero-G.
Hey
I hope someone can help me here.
I have a generally question to LinQ-mySQL with VB.NET
I have a table called customer. This table is related to an other table called orders. With LinQ, I am possible to do something like this:

Code: Select all

Dim Kunden = (From Query in DataContext.Customers Where Query.Name='MYNAME').Single
OK - Now, when I call:

Code: Select all

For each Auftrag In Kunden.Orders
Next
I can run through all orders of the customer.

But! - When I want to give the Variable: Kunden to an other form, how do I have to make this right, so I can call the For/Each in the new form, whitout loading the data again? (I know, that the Orders are loaded when they are called - deffered loading) - but will this also work between form and form, or how to do this right?

Hope you understand! - THX

Posted: Fri 21 Aug 2009 12:21
by AndreyR
I recommend you to use LoadWith() in the LINQ query that gets customer.
In this case the customer object will be passed with its orders collection.
Here is a sample code:

Code: Select all

Dim Kunden = (From Query in DataContext.Customers.LoadWith("Orders") Where Query.Name='MYNAME').Single

Posted: Fri 21 Aug 2009 12:28
by Zero-G.
Hey

Thanks for this answer.
This seems to be a good idea, by this example I gave to you.
But what about the situation, there are much more relations?
I talk about 20 relations between all the tables....

Is there another tipp?

THX

Posted: Fri 21 Aug 2009 12:45
by AndreyR
LoadWith() can be applied several times (for each relation, just don't forget to import Devart.Data.Linq namespace).
This will increase memory load, of course.
As an alternative, you can try to pass only the key of a customer and then query the necessary orders with the customer in a new form.