views:

111

answers:

1

I have two tables

Video

  • VideoId,
  • VideoName,
  • VideoUrl

Comment

  • CommId,
  • VideoId,
  • CommentDesc,
  • Rating

I want to join and get average rating for video using LINQ

How can I do this?

+1  A: 
var query = from video in Video join 
    comment in Comment on comment.VideoId equals video.VideoId;

Console.WriteLine("Average Rating: " + query
    .Where(i => i.VideoName = videoName)
    .Average(i => i.Rating));
Yuriy Faktorovich
If i want to get top 5 videoshow can i use order by Rating Desc and then take(5)
you could use query.GroupBy(i => i.VideoId, i => i, (ie, videoId) => new {VideoId = videoId, AverageRating = ie.Average(i => i.Rating)}).Take(5) the syntax might be a little off, I'm doing it from memory.
Yuriy Faktorovich