Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 1对多关系中2个类之间的Linq表达式_C#_Linq - Fatal编程技术网

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;