【发布时间】:2016-02-07 17:34:00
【问题描述】:
我有以下实体
- 项目
- 组件
- 项目组件
我想写一个类似的方法
GetProjectsByComponentId(int componentId)
{ /* some code*/}
请帮我写一个 lambda 表达式。
来自 EF 生成的架构的片段:
public partial class ProjectComponent
{
public int ID { get; set; }
public Nullable<int> ProjectID { get; set; }
public Nullable<int> ComponentID { get; set; }
public string Comment { get; set; }
public virtual Component Component { get; set; }
public virtual Project Project { get; set; }
}
public partial class Project
{
public Project()
{
this.ProjectComponents = new HashSet<ProjectComponent>();
}
public int ID { get; set; }
public string Description { get; set; }
public virtual ICollection<ProjectComponent> ProjectComponents { get; set; }
}
public partial class Component
{
public Component()
{
this.ProjectComponents = new HashSet<ProjectComponent>();
}
public int ID { get; set; }
public string Description { get; set; }
public virtual ICollection<ProjectComponent> ProjectComponents { get; set; }
}
【问题讨论】:
-
我想表达这样的查询...返回 ctx.Projects.Where(p => p...。我需要帮助如何完成该表达式
-
该示例正在寻找具有给定 ProjectId 的项目,这是不同的,另一个示例可能是项目和员工。获取与给定员工关联的所有项目。
标签: c# entity-framework lambda