C# 查询模型中的标记ID
我在多对多关系中有两个实体:C# 查询模型中的标记ID,c#,linq,asp.net-mvc-4,C#,Linq,Asp.net Mvc 4,我在多对多关系中有两个实体: public class SopFolder { public int Id { get; set; } public string Name { get; set; } public virtual ICollection<SopField> SopFields { get; set; } } public class SopField { public int
public class SopFolder
{
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<SopField> SopFields { get; set; }
}
public class SopField
{
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<SopFolder> SopFolders { get; set; }
}
如果要查找包含所有指定SOP字段的SOP文件夹,请尝试:
if (SopFolder.SopFields.All(x => fieldTags.Contains(x.Id))) { /* do stuff */ }
此查询正确且有效。我只是在递归文件夹循环中使用了错误的方法
if(SopFolder.SopFields.Any(x => fieldTags.Contains(x.Id))) { /* do stuff */ }
这实际上为我指明了正确的方向。我最初的查询是正确的,但我用错了。很高兴我能帮上忙?有几分?:)
if(SopFolder.SopFields.Any(x => fieldTags.Contains(x.Id))) { /* do stuff */ }