Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.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

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# Linq查询以获取具有多对一关系的项的所有属性_C#_Linq - Fatal编程技术网

C# Linq查询以获取具有多对一关系的项的所有属性

C# Linq查询以获取具有多对一关系的项的所有属性,c#,linq,C#,Linq,我有两个表/实体 public class Attribute { public int Id { get; set; } public string Name { get; set; } public string Details { get; set; } public bool Inactive { get; set; } public virtual ICollection<Item> Items{ get; set; }

我有两个表/实体

 public class Attribute
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Details { get; set; }
    public bool Inactive { get; set; }      
    public virtual ICollection<Item> Items{ get; set; }  
}

 public class Item
{
    public int Id { get; set; }
    public DateTime DateCreated { get; set; }
    public DateTime? DateModified { get; set; }
    public virtual ICollection<Attribute> Attributes  { get; set; }      
}
公共类属性
{
公共int Id{get;set;}
公共字符串名称{get;set;}
公共字符串详细信息{get;set;}
公共bool非活动{get;set;}
公共虚拟ICollection项{get;set;}
}
公共类项目
{
公共int Id{get;set;}
public DateTime DateCreated{get;set;}
公共日期时间?日期修改{get;set;}
公共虚拟ICollection属性{get;set;}
}

我试图找出Linq查询来检索属性非活动状态设置为false的项目ID的所有属性名称。属性计数可以是0到20。

以下内容应提供具有指定ID的项的所有属性名称

var selectedId = 1;  // The item ID you are looking for
var attrNames = items
    .Where(i => i.Id == selectedId)
    .SelectMany(x => x.Attributes)
    .Where(a => !a.Inactive)
    .Select(a => a.Name);

你试过用什么代码来做这件事?这就是问题所在,我在Linqpad中尝试的所有东西都无法让我接近提取我想要的数据。我将尝试发布最近的尝试。这是我被卡住的地方:Items.Take(100).where(s=>s.Attributes.where(a=>a.Inactive.Equals(false)))