linq 中这个 SQL 查询的等价物是什么
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;
如何在 linq 中编写此 sql 查询:
到目前为止,我已经完成了两次 returns 值:
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
};
我也试过:
var actorList_01 = actorList.Distinct();
但结果是一样的
试试这个
var matchingList = actorList
.GroupBy(x => x.ActorNumber )
.Select(g => g.First())
.ToList();
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;
如何在 linq 中编写此 sql 查询: 到目前为止,我已经完成了两次 returns 值:
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
};
我也试过:
var actorList_01 = actorList.Distinct();
但结果是一样的
试试这个
var matchingList = actorList
.GroupBy(x => x.ActorNumber )
.Select(g => g.First())
.ToList();