Note that there are some explanatory texts on larger screens.

plurals
  1. POLINQ to SQL, get most recent records for given ID
    text
    copied!<p>intHi,</p> <p>Pretty new to LINQ.</p> <p>I have a Ratings table.<br> A User adds a set of Ratings for an Entity There can be more than one Rating set for an Entity per User.</p> <p>For example, let's say the Entity is a car. The car is rated on Appearance and Performance. And a User can rate the given car's appearance and performance more than once. So my table looks something like this (the Rating field is not an Identity column; it is an int on a scale of 1 - 10):</p> <pre><code>ReviewID UserID EntityID CatID Rating Body DateSubmitted 1 3 6 1 7 "drives great" 8/01/2010 02:36:28 PM 2 3 6 2 8 "looks great" 8/01/2010 02:36:28 PM 3 3 6 1 2 "broke down" 8/18/2010 11:39:58 PM 4 3 6 2 1 "paint flaked off" 8/18/2010 11:39:58 PM </code></pre> <p>Now, I have a helper method where I supply the UserID and the EntityID and I want to return the most recent set of Ratings (into a ViewModel that includes the Rating Category).</p> <pre><code>public static IQueryable&lt;RatingViewModel&gt; GetRatingViewModel(int EntityID, int UserID) { DB _db = new DB(); var a = from rating in _db.Ratings join ratingCat in _db.RatingCategories on rating.RatingCategoryID equals ratingCat.RatingCategoryID where rating.UserID == UserID &amp;&amp; rating.EntityID == EntityID select new RatingViewModel { Rater = rating.User, RaterRating = rating, RatingCategory = ratingCat }; return a; } </code></pre> <p>What kind of "where" or "group by" or "order by" do I need to add to ONLY grab the most recent set of Ratings for the given UserID and EntityID? </p> <p>Thanks!</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