'What is the equivalent of this SQL query in linq

Select Distinct DVDTitle, CopyNumber from Actors a
inner join CastMembers b
on a.ActorNumber = b.ActorNumber
inner join DVDTitles c
on b.DVDNumber = c.DVDNumber
inner join DVDCopys d
on c.DVDNumber = d.DVDNumber;

How to write this sql query in linq: So far I've done this which returns value twice:

var actorList = from a in _db.Actors
                join b in _db.CastMembers
                on a.ActorNumber equals b.ActorNumber
                join c in _db.DVDTitles
                on b.DVDNumber equals c.DVDNumber
                join d in _db.DVDCopys
                on c.DVDNumber equals d.DVDNumber
                orderby c.DvdTitle
                                   

                select new Actor
                {
                     ActorNumber = a.ActorNumber,
                     ActorSurName = a.ActorSurName,
                     ActorFirstName = a.ActorFirstName,
                     DVDTitle = c.DvdTitle,
                     CopyNumber = d.CopyNumber
                };

I've also tried:

var actorList_01 = actorList.Distinct(); 

but the result is same.



Solution 1:[1]

try this

 var matchingList = actorList 
                .GroupBy(x => x.ActorNumber )
                .Select(g => g.First())
                .ToList();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 M Rizwan