【发布时间】:2011-05-12 19:23:57
【问题描述】:
考虑这种情况:
我有一个参考数据,我编写服务将其返回给我的客户。在我的程序中,我以不同的类型使用这些数据。
我想从客户端以动态方式从数据库中得到我想要的东西。
我想使用这样的代码:
public List<TResult> FindAll<T, TResult>(Func<T, bool> exp, Func<T, TResult> selector, int PageSize) where 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>();
}
}
因为:
函数中的订单充当参数而不是订单类。
我的 TResult 未在服务中声明
我该怎么做?非常感谢。
【问题讨论】:
-
EF 还是 LINQ to SQL?选择一个。
-
你能写出两者的答案吗?
标签: c# .net linq entity-framework linq-to-sql