[英]Returning the value of LINQ Query ASP.NET MVC5
在我的存儲庫類中,我有這個:
public xxxxx GetByxxxx(string value)
{
return context.xxxxx.Where(r => r.value== value).FirstOrDefault();
}
然后我像這樣在我的控制器中調用它
var result = ((xxxxRepo.GetByName(name)));
結果的值不斷返回 null,但 name 使用以下方法不斷返回 db 上的值:
System.Diagnostics.Debug.WriteLine("The result is " + result);
我錯過了什么。
你是返回對象。 所以當你打印值時使用這個。
System.Diagnostics.Debug.WriteLine("The result is " + result==null?"":result.Name);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.