简体   繁体   English

返回 LINQ 查询 ASP.NET MVC5 的值

[英]Returning the value of LINQ Query ASP.NET MVC5

In my repository class I have this:在我的存储库类中,我有这个:

public xxxxx GetByxxxx(string value)
{
    return context.xxxxx.Where(r => r.value== value).FirstOrDefault();
}

Then I am calling it in my controller like this然后我像这样在我的控制器中调用它

var result = ((xxxxRepo.GetByName(name)));

The value of result keeps returning null but name keeps returning the value on the db using:结果的值不断返回 null,但 name 使用以下方法不断返回 db 上的值:

System.Diagnostics.Debug.WriteLine("The result is " + result);

What am I missing.我错过了什么。

You are return object.你是返回对象。 So when you print value to use this.所以当你打印值时使用这个。

System.Diagnostics.Debug.WriteLine("The result is " + result==null?"":result.Name);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM