如何在 ASP.NET Core 3.1 的整数集合中查询整数数组?
How to query an array of integers in an integer collection in ASP.NET Core 3.1?
我想查询一个整数集合。现在,我只能按整数数组中的第一个值进行过滤。如何查询包含整数数组中所有值的博客标签id集合?
//list --> my blog posts variable
....
if (f.blogTagIds != null)
{
list = list.Where(p => p.BlogTagRelation.Select(p => p.BlogTagId).Contains(f.blogTagIds[0]));
}
....
搜索过滤器类
public class SearchFilterType
{
...
public int[] blogTagIds { get; set; }
...
}
ViewBag 博客标签
var BlogTags = new List<SelectListItem>();
foreach (var item in _uow.BlogTag.GetAllByEnabledDate(null, _uow.Cookie.GetAdminLangId, _uow.Cookie.GetAdminWebSiteId))
{
BlogTags.Add(new SelectListItem
{
Text = item.Title,
Value = item.Id.ToString()
});
}
ViewBag.BlogTags = BlogTags;
过滤表单 BlogTagIds Select 控件
<select asp-for="f.blogTagIds" class="form-control" multiple="multiple" asp-items="ViewBag.BlogTags"></select>
BlogTagRelation.cs
public partial class BlogTagRelation
{
public int Id { get; set; }
public int BlogId { get; set; }
public int BlogTagId { get; set; }
public virtual Blog Blog { get; set; }
public virtual BlogTag BlogTag { get; set; }
}
示例路线
/Blog/list?f.blogTagIds=8&f.blogTagIds=6
尝试:
var list =list.Where(x => blogTagIds.All(r => x.BlogTagRelation.Any(y => y.BlogTag.BlogTagId== r)));
确保所有 blogTagId 都包含在 BlogTagRelation
结果:
[我 select 具有特殊 roleId 的用户]
我想查询一个整数集合。现在,我只能按整数数组中的第一个值进行过滤。如何查询包含整数数组中所有值的博客标签id集合?
//list --> my blog posts variable
....
if (f.blogTagIds != null)
{
list = list.Where(p => p.BlogTagRelation.Select(p => p.BlogTagId).Contains(f.blogTagIds[0]));
}
....
搜索过滤器类
public class SearchFilterType
{
...
public int[] blogTagIds { get; set; }
...
}
ViewBag 博客标签
var BlogTags = new List<SelectListItem>();
foreach (var item in _uow.BlogTag.GetAllByEnabledDate(null, _uow.Cookie.GetAdminLangId, _uow.Cookie.GetAdminWebSiteId))
{
BlogTags.Add(new SelectListItem
{
Text = item.Title,
Value = item.Id.ToString()
});
}
ViewBag.BlogTags = BlogTags;
过滤表单 BlogTagIds Select 控件
<select asp-for="f.blogTagIds" class="form-control" multiple="multiple" asp-items="ViewBag.BlogTags"></select>
BlogTagRelation.cs
public partial class BlogTagRelation
{
public int Id { get; set; }
public int BlogId { get; set; }
public int BlogTagId { get; set; }
public virtual Blog Blog { get; set; }
public virtual BlogTag BlogTag { get; set; }
}
示例路线
/Blog/list?f.blogTagIds=8&f.blogTagIds=6
尝试:
var list =list.Where(x => blogTagIds.All(r => x.BlogTagRelation.Any(y => y.BlogTag.BlogTagId== r)));
确保所有 blogTagId 都包含在 BlogTagRelation
结果:
[我 select 具有特殊 roleId 的用户]