好的,我有这些表:
视频
VideoTag
代码
我需要一个LINQ to SQL查询来对视频执行搜索,通过标题或标签执行。
目前我所拥有的只是通过标题搜索:
IQueryable<Video> videos =
from v in ctx.Videos
where v.Title.Contains(SearchString)
select
new Video
{
Id = v.Id,
Title = v.Title
};
答案 0 :(得分:1)
试试这个:
from v in ctx.Videos
join vt in ctx.VideoTags on v.Id equals vt.VideoId
join t in ctx.Tag on vt.TagId equals t.Id
where v.Title.Contains(SearchString) || t.Name.Contains(SearchString)
select
new Video
{
Id = v.Id,
Title = v.Title
};