Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.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# 如何从客户端筛选行和选择所需列_C#_.net_Linq_Entity Framework_Linq To Sql - Fatal编程技术网

C# 如何从客户端筛选行和选择所需列

C# 如何从客户端筛选行和选择所需列,c#,.net,linq,entity-framework,linq-to-sql,C#,.net,Linq,Entity Framework,Linq To Sql,考虑以下情况: 我有一个参考数据,我写服务返回给我的客户。在我的程序中,我使用不同类型的数据 我希望以动态的方式从客户机的数据库中得到我想要的东西 我想使用这样的代码: public List<TResult> FindAll<T, TResult>(Func<T, bool> exp, Func<T, TResult> selector, int PageSize) where TResult : class { } publi

考虑以下情况:

我有一个参考数据,我写服务返回给我的客户。在我的程序中,我使用不同类型的数据

我希望以动态的方式从客户机的数据库中得到我想要的东西

我想使用这样的代码:

public List<TResult> FindAll<T, TResult>(Func<T, bool> exp, Func<T, TResult> selector, int PageSize) where TResult : class
{        
}
public List FindAll(Func exp,Func selector,int PageSize),其中TResult:class
{        
}
问题是我不能将我的服务接口声明为泛型,也不能以这种方式使用该代码:

public List<TResult> FindAll<Order, TResult>(Func<Order, bool> exp, Func<Order, TResult> selector, int PageSize) where TResult : class
{
    using (DataClasses1DataContext dc = new DataClasses1DataContext())
    {
        return dc.Orders.Where(exp).Select<Order, TResult>(selector).ToList<TResult>();
    }
}
public List FindAll(Func exp,Func selector,int PageSize),其中TResult:class
{
使用(DataClasses1DataContext dc=newdataclasses1datacontext())
{
返回dc.Orders.Where(exp).Select(selector.ToList();
}
}
因为:

  • 函数中的Order用作参数,而不是Order类

  • 我的TResult未在服务中声明


  • 我怎么能做到?非常感谢。

    您不能将方法设置为泛型,不能将委托作为参数传递,也可能无法将表达式树作为参数传递,因为我认为默认情况下它是不可序列化的。您应该使用一些已经为您做到这一点的API—检查或。

    EF或LINQ to SQL?选择一个。你能写两个的答案吗?