0

我需要在 LINQ to Entities 中模仿这一点:

WHERE 
(title = 'title1' AND episodetitle = 'episodetitle1')
OR
(title = 'title2' AND episodetitle = 'episodetitle2')

我试过这个:

if (title1 != null && episodeTitle1 != null)
{
      query = query.Where(s => s.Title.Contains(title1)).Where(z => z.EpisodeTitle.Contains(episodeTitle1));
}

if (title2 != null && episodeTitle2 != null)
{
      query = query.Where(s => s.Title.Contains(title2)).Where(z => z.EpisodeTitle.Contains(episodeTitle2));
}

但它给了我这个:

([Extent1].[Title] LIKE @p__linq__0 ESCAPE '~') AND ([Extent1].[EpisodeTitle] LIKE @p__linq__1 ESCAPE '~') 
**AND**
 ([Extent1].[Title] LIKE @p__linq__2 ESCAPE '~') AND ([Extent1].[EpisodeTitle] LIKE @p__linq__3 ESCAPE '~')}

我需要将上面的AND更改为 OR。

我该怎么做呢?

4

1 回答 1

2

在一个查询中连接它

query.Where(
s => (
( title1!=null && episodeTitle1!=null && s.Title.Contains(title1) && s.EpisodeTitle.Contains(episodeTitle1) )
||
( title2!=null && episodeTitle2!=null && s .Title.Contains(title2) && s.EpisodeTitle.Contains(episodeTitle2) )
于 2013-06-26T17:51:42.337 回答