我有 C# Lambda linq 查询如下:
public IQueryable<CtArticleDetail> GetArticleDetailsByTagNames(string tagNames)
{
return db.CtArticleTags.Where(m => tagNames.Contains(m.CtTag.Name)
&& m.CtArticleDetail.ExpirationDate > DateTime.Now
&& m.CtArticleDetail.ArticleStatusId == (int)ArticleStatus.Published)
.Select(m => m.CtArticleDetail).OrderBy(x => x.LiveDate).Distinct();
}
由于“包含”,这会返回稍微错误的数据列表。参数实际上是这样的格式:EG(“AterSale,GeneralSale”)。结果列表包含其他销售类型的文章.EG(“Sale”或“ImportedSale”)。
reuslt 列表应该是作为参数传递的确切列表。有人可以请教吗?
var mustContain = new[] {"A", "B");
var foos = new List<Foo>(){
new Foo1 {Tags = "A"},
new Foo1 {Tags = "B"},
new Foo2 {Tags = "A"},
new Foo2 {Tags = "C"}
};
如果 mustcontain 是 A,B,我只需要 Foo1