我在 Visual Studio 2012 中使用实体框架代码优先技术这是我的上下文
public class BakingWebContext : DbContext
{
        public DbSet<Recipe> Recipes { get; set; }
        public DbSet<Category> Categories { get; set; }
}
我有一个类别类
public class Category
{
        [Key]
        public int CategoryId { get; set; }
        [Required]
        public string Name { get; set; }
        public string Description { get; set; }
        public string ImageUrl { get; set; }
        public virtual ICollection<Recipe> Recipes { get; set; }
}
它包含食谱的虚拟集合
public class Recipe
{
        [Key]
        public int RecipeId { get; set; }
        [Required]
        public string Title { get; set; }
        public string Description { get; set; }
        public bool IsCompanyRecipe { get; set; }
}
我正在尝试返回所有类别,包括仅使用 C# 中的 Lambda 表达式将IsCompanyRecipe标记为true的食谱
到目前为止,我有这个
var query = categories.Where(c => c.Recipes.Count > 0).SelectMany(r => r.Recipes.Where(re => re.IsCompanyRecipe == true));
它返回IEnumerable<Recipe>所有公司食谱的列表,但我想返回一个IEnumerable<Category>包含所有食谱的列表,在哪里IsCompanyRecipe == true?