Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.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# EF核心中的条件包含_C#_Asp.net_Entity Framework_Asp.net Core_Entity Framework Core - Fatal编程技术网

C# EF核心中的条件包含

C# EF核心中的条件包含,c#,asp.net,entity-framework,asp.net-core,entity-framework-core,C#,Asp.net,Entity Framework,Asp.net Core,Entity Framework Core,因此,在我的查询中,我有多个参数,然后包括所有相关数据。在最后一个include语句中,我想添加一个条件,但由于我的linq语句,我得到了一个“无效lambda表达式”响应 Class Sample1 { public int Id { get; set; } public ICollection<Sample2> S2 { get; set;} } Class Sample2 { public Sample3 S3 { get; set; } public

因此,在我的查询中,我有多个参数,然后包括所有相关数据。在最后一个include语句中,我想添加一个条件,但由于我的linq语句,我得到了一个“无效lambda表达式”响应

Class Sample1 
{
   public int Id { get; set; }
   public ICollection<Sample2> S2 { get; set;}
}
Class Sample2
{
   public Sample3 S3 { get; set; }
   public Sample1 S1 { get; set;}
}
Class Sample3
{
   public int Id { get; set; }
   public ICollection<Sample4> S4 { get; set;}
}
Class Sample4 
{
   public Sample3 S3 { get; set; }
   public Sample5 S5 { get; set;}
}
Class Sample5
{
   public int Id { get; set; }
   public bool isPresent { get; set;}
}
我尝试过使用Any而不是Where,但也没有效果。
我非常感谢在这方面提供的任何帮助。我尝试过按照相关问题的一些答案所建议的做,但似乎没有一个奏效。

实体框架核心3.1

在Entity Framework Core 3.1中仍然没有选项,以下是公开的问题:

这在几天前添加到里程碑5.0.0的待办事项中

您应该尝试使用或类似的扩展。否则,您可以将lambda与查询表达式混合使用。请参阅此主题:


实体框架核心5.0及以上版本

过滤包含在EF Core 5.0中引入

var filteredBlogs = context.Blogs
        .Include(
            blog => blog.Posts
                .Where(post => post.BlogId == 1)
                .OrderByDescending(post => post.Title)
                .Take(5))
        .ToList();

这里的更多信息:

谢谢,这真是一个令人不快的问题。我想避免使用queryfilter,因为这会给我太多的方法,我必须添加ignorequeryfilter,我认为它给出了错误的需求/必要性,但我宁愿使用ef与原始sql的过度混合。您可能希望将答案更新为5。0确实带来了此功能:
var filteredBlogs = context.Blogs
        .Include(
            blog => blog.Posts
                .Where(post => post.BlogId == 1)
                .OrderByDescending(post => post.Title)
                .Take(5))
        .ToList();