我有以下數據庫: 使用LINQ搜索關係數據庫
和下面的代碼:
public IActionResult Index(IssueModel searchCriteria)
{
var bloods = from m in _context.Blood
select m;
if (!string.IsNullOrEmpty(searchCriteria.SearchComponent))
{
//Blood Component
bloods = bloods.Where(s => s.Component.Contains(searchCriteria.SearchComponent));
//Blood Type : This is where I plan to search for a specific blood type.
}
return View(bloods);
}
正如你所看到的,我很高興來搜索數據庫血液在一定組件類型。在我標記的區域中,我想搜索與特定PlasType或RedBloodType相關的血液。
任何想法?謝謝!
編輯:感謝所有提供了答案的人。我所看到的所有答案都非常有用,不僅幫助我破解這個問題,還提高了我對該主題的理解。
你'return'聲明忽略'bloods'是無益的事實......但此外,你還沒有真正問了一個問題呢。你究竟在幹什麼? –
您可以繼續查詢。鑑於'blood.DonorId',你可以找到符合你的'PlasmaType'和'RedBloodType'標準的'Donor'。然後,返回查詢結果,而不是原始的'_context.Blood.List' – Ian