【问题标题】:query base object based on a non related entity list using entity framework使用实体框架基于非相关实体列表查询基础对象
【发布时间】:2012-06-05 09:57:27
【问题描述】:

我有以下型号:

工作流配置有一个品牌,也有一个类型。 工作流配置有一组审批者。 Approvers 实体具有属性 Status 和 username。

在应用程序的另一部分,我们有一个名为 RequestBase 的实体 该实体有一个名为 CurrentStatus 的字符串属性。

我需要使用 linq 或 EF Lambda 表达式进行查询,返回所有状态与批准者实体上的用户名匹配的请求。 我知道它有点复杂,或者真的很复杂,哈哈。

这些是我的实体(简体)

public class RequestBase
    {
        public int RequestBaseId { get; set; }
        public string CurrentStatus { get; set; }
      }


 public class WorkflowConfiguration
    {
        public int WorkflowConfigurationId { get; set; }
        public WorkflowType WorkflowType { get; set; }
        public Brand Brand { get; set; }
        public virtual ICollection<Approver> Approvers { get; set; }

    }


public class Approver
    {
        public Approver()
        {

        }

        public Approver(string approverUserName)
        {
            Name = approverUserName;
        }

        public int Id { get; set; }
        public string Name { get; set; }
        public string StepName { get; set; }  -----||||>>>>>> Must match status?
        public int Order { get; set; }
    }

我的查询呢? 显然它甚至没有编译

return _context.RequestBases.
                        .Where(a => a.CurrentStatus.Any(workflowconfiguration.Select(b=>b.Approvers.Select(c => c.StepName))));

【问题讨论】:

    标签: c# linq entity-framework entity-framework-4 entity-framework-4.1


    【解决方案1】:
    _context.RequestBases
    .Where(rb => _context.Workflowconfiguration
        .Any(wc => wc.Approvers
            .Any(a => a.StepName == rb.CurrentStatus)));
    

    【讨论】:

      最近更新 更多