繁体   English   中英

如何使用每个请求的状态检索此请求列表?

[英]How to retrieve this list of requests with the status of each request?

我是新的ASP.NET Webforms开发人员。 我现在正在学习如何使用实体框架和存储库模式。 我现在正在努力的是如何从TRequest表中检索请求列表以及每个请求的批准状态。 这是我的数据库架构:

TRequest: Id, Title, Reason
TApproval: Id, RequestId, StatusId
TStatus: Id, Title

我要做的是检索请求列表,包括每个请求的状态。

在我的存储库模式中,我有以下代码:

public IEnumerable<TRequest> GetRequest()
{
    return context.TRequest.ToList();
}

public IEnumerable<TRequest> GetRequestByStatus(int statusId)
{
    return GetRequests().Where(r => r.TApproval.TStatus.Id).ToList();   //I got an error here
}

为什么第二种方法GetRequestByStatus出现错误? 我无法说r.TApproval.TStatus.Id ,我也不知道为什么。

为什么第二种方法GetRequestByStatus出现错误? 我无法>说出r.TApproval.TStatus.Id,我也不知道为什么。

Where方法需要一个谓词,而您不会在此传递谓词。 MSDN中所述,更正式地讲。

查询表达式中使用where子句,以指定将在查询表达式中返回数据源中的哪些元素。 它将布尔条件(谓词)应用于每个源 元素(由range变量引用),并返回其 指定条件为true的 那些元素 单个查询表达式可以包含多个where子句,而单个子句可以包含多个谓词子表达式。

如果您尝试按状态ID进行过滤,则需要将行更改为

return GetRequests().Where(r => r.TApproval.TStatus.Id == statusId).ToList();

暂无
暂无

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

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