How to question

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
Zero-G.
Posts: 398
Joined: Sat 09 Dec 2006 12:20

How to question

Post by Zero-G. » Fri 21 Aug 2009 08:55

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

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Fri 21 Aug 2009 12:21

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

Zero-G.
Posts: 398
Joined: Sat 09 Dec 2006 12:20

Post by Zero-G. » Fri 21 Aug 2009 12:28

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

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Fri 21 Aug 2009 12:45

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.

Post Reply