Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.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 Core 3中维护干净的代码_C#_Linq_Entity Framework Core - Fatal编程技术网

C# 避免客户评估,同时在EF Core 3中维护干净的代码

C# 避免客户评估,同时在EF Core 3中维护干净的代码,c#,linq,entity-framework-core,C#,Linq,Entity Framework Core,我需要向数据库中写入更复杂的查询在客户端评估的情况下,很容易维护干净的代码,但我要处理大量数据,需要保持后端快速。 客户实体就是一个很好的例子。我的查询现在是这样的: public class CustomerFilter : AbstractProjectFilter { public CustomerFilter(string query, bool includeNotSet, ICollection<string> customers) : base(

我需要向数据库中写入更复杂的查询在客户端评估的情况下,很容易维护干净的代码,但我要处理大量数据,需要保持后端快速。

客户实体就是一个很好的例子。我的查询现在是这样的:

public class CustomerFilter : AbstractProjectFilter
{
    public CustomerFilter(string query, bool includeNotSet, ICollection<string> customers) :
        base(e => (customers == null)
                  || (includeNotSet && e.Customer == null)
                  || (customers.Contains("Company") && e.Customer.Type == CustomerType.Company &&
                      EF.Functions.Like((((CustomerCompany)e.Customer).Name + " " + ((CustomerCompany)e.Customer).Crn + " " + ((CustomerCompany)e.Customer).VatRegNo), "%" + query + "%"))
                  || (customers.Contains("Person") && e.Customer.Type == CustomerType.Person &&
                      EF.Functions.Like(((CustomerPerson)e.Customer).Forename + " " + ((CustomerPerson)e.Customer).Surname, "%" + query + "%"))
                  || (customers.Contains("Evidence") && e.Customer.Type == CustomerType.InEvidence &&
                      EF.Functions.Like(e.Customer.EvidenceName, "%" + query + "%"))
        )
    {
    }
}
我的问题:有没有一种方法可以告诉数据库如何处理方法而不需要从中获取数据?我缺少Fluent API的一些配置?

如果我能够在使用Linq.Dynamic进行排序时使用这些“方法”也会很好,如下所示:

var orderedCustomers = await customers.OrderBy("*string_created_by_some_method* ASC").ToListAsync();
有没有一种方法可以告诉数据库如何处理方法而不需要从中获取数据?我缺少的Fluent API的一些配置

没有任何简单的方法,这种方法正是
表达式的含义

在不获取数据的情况下与数据库对话的唯一方法是使用
表达式。它不是很直,但可以做你需要的一切


你可以看到一个例子

我的天啊,用表达式来表达这一点其实很简单。不知道为什么我自己没想到。非常感谢。
var orderedCustomers = await customers.OrderBy("*string_created_by_some_method* ASC").ToListAsync();