我在互联网上搜索了这个问题的答案,但没有运气。我有一个模型存在于使用实体框架创建的数据库中,并通过 db(我的 DBContext 类的一个实例)进行访问。
Function Details(id As Integer) As ViewResult
Dim bill As Bill = db.Bills.Find(id)
Return View(bill)
End Function
票据类的模型定义为:
Public Class Bill
Public Property BillId() As Integer
Public Property CustomerId() As String
Public Property BillStatus() As String
End Class
假设在首先提到的函数中,我传递了 CustomerId 而不是这个模型的主键 (BillId),我将如何使用它来创建一个“Dim bill As Bill”,其中仅包含具有该 customerId 的账单。
就像上面的例子一样,账单是用 .Find(id) 过滤的——它只查看主键——我希望能够使用与 .Find() 类似的方法,但在非关键字段上:在这种情况下为 CustomerId .