Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok,</p> <p>For efficiency reason, I decided to go with custom DTO object that fetches the localized information and flatten the result.</p> <p>But, the same problem occurred when my custom DTO needed to reference another custom localized DTO.</p> <p>Here is how I came to do the same as the .Include( "PropertyName" ) that the ObjectSet offers:</p> <p>Entity <strong>LocalizedMovieCollection</strong></p> <pre><code>public class LocalizedMovieCollection { [Key] public int Id { get; set; } public string Name { get; set; } (the result of a sub query based on the language) [Include] [Association( "LocalizedMovieCollection_LocalizedMovies", "Id", "MovieCollection_Id" )] public IEnumerable&lt;LocalizedMovie&gt; Movies { get; set; } } </code></pre> <p>Entity <strong>LocalizedMovie</strong></p> <pre><code>public class LocalizedMovie { [Key] public int Id { get; set; } public string Name { get; set; } (the result of a sub query based on the language) public int MovieCollection_Id { get; set; } [Include] [Association( "LocalizedMovie_LocalizedMovieCollection", "MovieCollection_Id", "Id", IsForeignKey = true] public LocalizedMovieCollection MovieCollection { get; set; } } </code></pre> <p>Then, I've declared two methods: One that returns an <strong>IQueryable of LocalizedMovieCollection</strong> and the other, an <strong>IQueryable of LocalizedMovie</strong>. (Note: There must be at least one method that returns each type of entity for the entity to get auto-generated on the Silverlight client)</p> <p>My goal is to automatically load the MovieCollection associated with a Movie so the method definition to get the movies is as follow:</p> <pre><code>public IQueryable&lt;LocalizedMovie&gt; GetMovies( string languageCode ) { return from movie in this.ObjectContext.Movies join movieLocalizedInfo in this.ObjectContext.MovieLocalizedInformations on movie equals movieLocalizedInfo.Movie join movieCollection in this.ObjectContext.MovieCollections on movie.MovieCollection equals movieCollection join movieCollectionLocalizedInfo in this.ObjectContext.MovieCollectionLocalizedInformations on movieCollection equals movieCollectionLocalizedInfo.MovieCollection where movieLocalizedInfo.LanguageCode == languageCode &amp;&amp; movieCollectionLocalizedInfo.LanguageCode == languageCode select new LocalizedMovie() { Id = movie.Id, Name = movieLocalizedInfo.Name MovieCollection_Id = movieCollection.Id, MovieCollection = new LocalizedMovieCollection(){ Id = movieCollection.Id, Name = movieCollectionLocalizedInfo.Name } } } </code></pre> <p>When the Silverlight client loads the query, all the <em>LocalizedMovies</em> and their associated <em>LocalizedMovieCollections</em> will be loaded into the context.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload