How can I execute this collection, group by query in LINQ?

Please do not give me a full working example, I want to know how to do this, and not get the code that I can copy to the folder

This is a query that I need and cannot create it for me in LINQ.

SELECT * FROM
dbo.Schedules s, dbo.Videos v
WHERE s.VideoID = v.ID
AND s.ID IN 
(
    SELECT MAX(ID) FROM dbo.Schedules
    WHERE ChannelID = 1
    GROUP BY VideoID
)
ORDER BY v.Rating DESC, s.StartTime DESC

I have a "IN" query in LINQ, I think something like this

var uniqueList =  from schedule in db.Schedules
                  where schedule.ChannelID == channelID
                  group schedule by schedule.VideoID into s
                  select new
                  {
                      id = s.Max(i => i.ID)
                  };

Maybe this is wrong, but now I can not check another request for this in the where clause uniqueList.Contains(schedule.ID)

Perhaps there is a better way to write this query, if you have an idea, I would like some tips.

I get this error and it doesn’t make much sense.

Type arguments for the 'System.Linq.Queryable.Contains (System.Linq.IQueryable, TSource)' method cannot be taken out of use. Try explicitly specifying type arguments.

+3
1

.Where(sInner = > s.ID == sInner.ID).Any().

. linq . , , , , , , , .

+2

Source: https://habr.com/ru/post/1745361/


All Articles