【发布时间】:2021-02-28 13:33:12
【问题描述】:
我是 C# 编码的初学者(实际上是一般的编码),我正在尝试创建一个网站来同时搜索 SQL Server 数据库中的多个和/或单个条件。到目前为止,它对于单个条件来说就像一个魅力,而且速度非常快,但到目前为止我还无法呈现多个条件搜索。我到处寻找可能的解决方案,但空手而归,要么是因为我还不知道如何实现它,要么是因为有些方法似乎不再起作用,包括多个 where 子句 && 和 | | where 子句和一些 Microsoft 教程中的运算符。
这是我的控制器:
var Projektdokumenter = from p in _context.ProjekterDokutypeDokuundertype
.Include(p => p.Dokumenttype)
.Include(p => p.Dokuundertype)
.Include(p => p.Forfatter)
.Include(p => p.P)
.Include(p => p.Sprog)
select p;
if (!String.IsNullOrEmpty(searchString) || (searchProject) != null)
{
if (!String.IsNullOrEmpty(searchString))
{
return View(Projektdokumenter.Where(p => p.Forfatter.Initialer.Contains(searchString)).ToList());
}
{
if (searchProject.HasValue)
{
return View(Projektdokumenter.Where(p => p.P.ProjektId.Equals(searchProject)).ToList());
}
}
}
这是我的观点
<form asp-action="Index" method="get">
<div>
<p>
Forfatter Initialer: <input type="text" name="searchString" value"" />
Projekt ID: <input type="number" name="searchProject" value"" />
<input type="submit" value="Search" class="btn btn-primary" />
<a asp-action="Index">Remove Filter</a>
</p>
</div>
</form>
【问题讨论】:
-
您是说希望用户输入“Foo && Bar”并让 EFCore 将其解释为 AND 查询?
标签: asp.net-core asp.net-core-mvc ienumerable iqueryable