Chris
Chris

Reputation: 7611

LINQ to SQL LoadWith

I'm trying to use LoadWith in LINQ to SQL to select another table at the same time as the others being selected. However, I've tried the following code:

DataLoadOptions options = new DataLoadOptions();
options.LoadWith<Account>(a => a.Purchases);
dc.LoadOptions = options;

However, the only properties of 'a' are the fields on the Account table, so it doesn't compile. What am I doing wrong?

Upvotes: 2

Views: 1102

Answers (1)

sajoshi
sajoshi

Reputation: 2763

LoadWith works only with the entities where reletionship is defined. If you have not defined the foreign key relationship for Account with Purchase... This will definitely give error. Please check that both the entities are linked via a foreign key.

Take a look at the Northwind example here: http://msdn.microsoft.com/en-us/library/bb534268(v=VS.90).aspx

Upvotes: 2

Related Questions