linq - 我可以使用 .net core 3.1 中的连接表过滤 IQueryable 中的查询吗
问题描述
我有一个 IQeryable 作为具有多个输入的过滤器功能(为了清楚起见,我排除了一些):
public IActionResult Index(... searchType, string searchUndertype ...)
{
var query = _context.ProjektDokument
.Include(p => p.Dokumenttype)
.Include(p => p.DokuUndertype)
...
.AsQueryable();
if (!string.IsNullOrEmpty(searchType))
{
query = query.Where(p => p.Dokumenttype.Dokumenttype1.Contains(searchType));
}
if (!string.IsNullOrEmpty(searchUndertype))
{
query = query.Where(p => p.DokuUndertype.DokuUndertype1.Contains(searchUndertype));
}
return View(query.ToList());
}
这完美地工作。现在,用户想要添加一个功能,其中 Dokumenttype1 或 DokuUndertype1 的输入框中的结果被另一个过滤,因此只有已经创建的 DokumenttypeDokuUndertype 对在任一输入框中被选中,例如,如果您在dokumenttype1,您只会获得 A 在 dokumenttype1 中的所有实例,反之亦然。为此,我创建了一个连接表:
{
public partial class DokumenttypeDokuUndertype
{
public int Id { get; set; }
public int DokumenttypeId { get; set; }
public int DokuUndertypeId { get; set; }
public virtual DokuUndertype DokuUndertype { get; set; }
public virtual Dokumenttype Dokumenttype { get; set; }
}
}
我的问题是,我该怎么做?我曾尝试通过布尔运算符将连接表包含在变量查询中,但无济于事。我已经尝试过.ThenInclude,并再次删除。我想也许视图模型可能是要走的路,但不太知道该怎么做。
你们有什么建议吗?(我使用了数据库优先方法)
解决方案
推荐阅读
- asp.net-core - 将 Edge Chromium 与 Windows 身份验证一起使用时,SignalR WebSockets 连接失败
- vb.net - 我将如何修复 versioncheck.vbs 中的错误 9009
- c# - Swashbuckle Swagger 生成一个实际的 guid
- powershell - 如何使用 PowerShell 为新的通讯组设置传入电子邮件 Active Directory 容器
- android - TTS 不与连接的耳机通话
- python-3.x - Snakemake 在空运行时产生非常不连贯的错误
- reactjs - 附加 d3 圆的高度和宽度太大
- r - 为什么我的代码在我向表中输入数据之前会运行多次?如何制作在 ui 中创建表格的操作按钮?
- session - Firmware update fails from SYSTEM session but works when ran from logged on session?
- python - 在具有不同键的字典字典中搜索值的最 Pythonic 方法是什么?