I have the following entities in my dbml: (made up for an example)
Book <- Media -> AuthorsForMedia <- Author
The arrows are the relationships in my dbml.
A book is a type of media, and an instance of a book has a media property with the values common to all media in it. AuthorsForMedia is an intersecting table with an AuthorId, a MediaId, and an AuthorsForMediaId.
My get query in my repository is:
public Book Get(int id)
{
var query = from b in db.Books
where b.BookId == id
select b;
return query.Single();
}
The resulting object has the book properties set, and media property with all of its values set.
When I look at AuthorsForMedia in the Watch dialog while debugging, the following values are set:
Count = 0
HasLoadedOrAssignedValues = false
IsDeferred = false
Why can't the values for AuthorsForMedia (and then its corresponding Author property) be evaluated with lazy loading?
After reading this question:
I tried the DataLoadOptions with LoadWith/AssoicateWith and it didn't work. I ended up with errors like
I can supply code snippets for all of this if it helps, but I think its a conceptual issue not a syntatic one.
How should I be retrieving these values, should it be a left join, or something else I haven't found so far?
This is how the LoadWith should look.
DataLoadOptions dlOptions = new DataLoadOptions();
dlOptions.LoadWith<Books>(book => book.AuthorsForMedia);
db.LoadOptions = dlOptions;