我有一个非常大的linq查询驱动我的系统的一部分,我试图添加一个新功能,但连接似乎是行为不端。
旧查询用于恢复我用于创建视图模型的视频列表,并且仅列出每个视频一次,并显示所有元数据VisibleStaff
,VisiblePlayers
和{{ 1}}都是IEnumerable。
由于添加了驱动器VisibleTeams
,所以VisibleStaff
中VideosLinkings
标志设置为人员的条目的任何视频,每个条目显示一次,而不是一次,并给出我将工作人员列表作为VideoInType
的元数据。
我想我错过了某个地方的分组,但我在多个地方尝试了多个小组,似乎无法做到正确。
有没有人知道我的联接哪里出错了,以及我如何在每个VideoModel中返回一个视频和多个人员?
完整查询
VisibleStaff
新行
from video in Videos
where
video.ClubID == ClubId &&
(VideoFilter.Category == 0 || video.VideoCategoryID == VideoFilter.Category)
join userStaff in Database.Users on video.AddedByUserID.Value equals userStaff.UserID
join videoInTeams in VideoInTeams on video.VideoID equals videoInTeams.VideoID into teamsForVideo
join playerInVideo in Database.PlayersVideos on video.VideoID equals playerInVideo.VideoId into
playersForVideo
join soapVideoLink in Database.VideosLinkings on new {a = video.VideoID, b = VideoInType.SOAPNote}
equals new {a = soapVideoLink.VideoId, b = soapVideoLink.VideoInType} into soapVideoLinks
join staffVideoLink in Database.VideosLinkings on new {a = video.VideoID, b = VideoInType.Staff}
equals new {a = staffVideoLink.VideoId, b = staffVideoLink.VideoInType} into
staffVideoLinks
from svl in staffVideoLinks.DefaultIfEmpty()
join staff in Staff on svl.VideoInKeyId equals staff.StaffID into visibleStaff
let soapLinks = soapVideoLinks.Any(f => f.VideoInKeyId != -1)
let oldExtension =
video.H264Version == "Uploaded"
? ".mp4"
: (video.FlashVersion == "Uploaded" ? ".flv" : video.FileExtension)
where
VideoFilter.ShowSoapVideos || (VideoFilter.ShowSoapVideos == false && soapLinks == false)
orderby video.DateTimeUploaded descending
select new VideoModel
{
Video = video,
Category = video.VideoCategory,
Staff = userStaff.Staff,
ShowDeleteOption = VideoFilter.ShowDeleteOption,
VisibleTeams = teamsForVideo.Select(f => f.Team),
VisiblePlayers = playersForVideo.Select(f => f.Player),
Thumbnail =
video.ThumbnailURL != "" && video.ThumbnailURL != null
? video.ThumbnailURL
: "/Images/Videos/noimage.png",
IsNew = false,
IsMedicalVideo = soapLinks,
VisibleStaff = visibleStaff,
IsStaffVideo = staffVideoLinks.Any()
}