C# 如何为实体框架中的所有子级使用条件

C# 如何为实体框架中的所有子级使用条件,c#,entity-framework,linq,C#,Entity Framework,Linq,我有以下课程: public class product { public int Id { get; set; } public string Title { get; set; } public Store Store { get; set; } public ICollection<Color> Colors { get; set; } } public class Color { public int Id { get; set;

我有以下课程:

public class product
{
    public int Id { get; set; }
    public string Title { get; set; }
    public Store Store { get; set; }

    public ICollection<Color> Colors { get; set; }
}

public class Color
{
    public int Id { get; set; }
    public string Name { get; set; }
    public product Product { get; set; }
}

public class Store
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string City { get; set; }

    public ICollection<product> Products { get; set; }
}

如何执行此操作?

通过方法语法执行此操作:

var stlist = Stores.Where(s => s.Name.ToLower() == "lilo" && s.Products.Where(p => p.Colors.Any(c=>c.Name=="Blue") && p.Title == "Dell").FirstOrDefault().Title == "Dell").ToList(); 
更新: 和的答案是(最佳答案):

林克:

    var test = (from s in Stores
                   from p in s.Products
                   from c in p.Colors
                   where s.Name=="Lilo" && p.Title=="Dell"&& c.Name=="Blue" 
                   select s
                   ).ToList();

您所说的实体框架的
是什么意思?您的意思是使用
实体SQL
?LinqToEntity是最合适的工具(避免容易出错),也是EF中最常用的工具,不知道为什么您不想使用LINQ(您的代码甚至使用LINQ-它是用来表达您想要的吗?)您想要所有的存储,所以从您的数据来看,您想要的应该像这样表示所有存储都有任何名为“Dell”的产品这些产品应该至少有一种颜色为“蓝色”。因此,查询可以是这样的:代码>存储。在哪里(s= > s name=“LILO”& & s产品。任何(P=>P title=“戴尔”和.P.颜色)。(C= > C.Clopy.Name=“蓝色”)).@Apaple感谢它的工作。尝试添加一个方法语法版本,他想要方法语法,您很快就会有一个可接受的答案。@Apaple您的权利,好的,将其更改为方法语法或删除我的答案。将其更改为方法语法并通知他答案,一个问题应该有一个可接受的答案。此外,我的评论中的查询已确认有效,因此您可以在回答中使用相同的查询:)(很难有所不同)
var stlist = Stores.Where(s => s.Name.ToLower() == "lilo" && s.Products.Where(p => p.Colors.Any(c=>c.Name=="Blue") && p.Title == "Dell").FirstOrDefault().Title == "Dell").ToList(); 
 var lslist2= Stores.Where(s => s.Name == "lilo" && s.Products.Any(p => p.Title == "Dell" && p.Colors.Any(c => c.Color.Name == "Blue"))).ToList();
    var test = (from s in Stores
                   from p in s.Products
                   from c in p.Colors
                   where s.Name=="Lilo" && p.Title=="Dell"&& c.Name=="Blue" 
                   select s
                   ).ToList();