C# 1对多关系中2个类之间的Linq表达式
我有两门课:C# 1对多关系中2个类之间的Linq表达式,c#,linq,C#,Linq,我有两门课: public class Op { [Key] public int OpId { get; set; } private OpportunitiesDb db = new OpportunitiesDb(); [Required(ErrorMessage = "Opportunity title is required")] [DisplayName("Opportunity Title")] public string Tit
public class Op
{
[Key]
public int OpId { get; set; }
private OpportunitiesDb db = new OpportunitiesDb();
[Required(ErrorMessage = "Opportunity title is required")]
[DisplayName("Opportunity Title")]
public string Title { get; set; }
[DisplayName("Tags")]
public ICollection<Tags> Tags { get; set; }
}
public class Tags
{
[Key]
public int Id { get; set; }
public int OpId { get; set; }
public string Tag { get; set; }
}
分组依据
Tag
from r in db.Tags
join o in db.Ops on r.OpId equals o.OpId
group o by r.Tag into ops
select ops
按标记筛选以获取您正在查找的Ops我需要的是此搜索,这将在字符串查询变量中显示所有具有相同标记的Ops:
var AllOpsWithTagQuery = from r in db.Tags
where(r.Tag.StartsWith(Query))
join o in db.Opportunities on r.OpId equals o.OpId
select o;
这对我不起作用。它应该带来所有具有给定“标签”的操作
var AllOpsWithTagQuery = from r in db.Tags
where(r.Tag.StartsWith(Query))
join o in db.Opportunities on r.OpId equals o.OpId
select o;