Linq to sql 如何定义退货清单<;T>;对于LinqToSql联接?

Linq to sql 如何定义退货清单<;T>;对于LinqToSql联接?,linq-to-sql,join,Linq To Sql,Join,我在DAL层中使用Linq到Sql连接查询,如何为LinqToSql连接方法自动定义一个返回List 现在,我必须为每个LinqToSql连接方法的返回值手动定义一个列表 是否可以像以下代码一样定义列表: public static List<T> GetJoinList() { List<T> list = new List<T>(); list = from c in customers join o in or

我在DAL层中使用Linq到Sql连接查询,如何为LinqToSql连接方法自动定义一个返回
List

现在,我必须为每个LinqToSql连接方法的返回值手动定义一个
列表

是否可以像以下代码一样定义
列表

public static List<T> GetJoinList()
{
    List<T> list = new List<T>();

    list =  from c in customers
            join o in orders on o.customerid equals c.customerid
            select new { CustomerID = c.CustomerId, OrderDate = o.OrderDate } ;

    return list.ToList() ;
}
publicstaticlist GetJoinList()
{
列表=新列表();
列表=来自客户中的c
在o.customerid等于c.customerid的订单中加入o
选择new{CustomerID=c.CustomerID,OrderDate=o.OrderDate};
return list.ToList();
}

事实上,我的意思是如何将匿名类型列表从DAL层传递到BLL层?

您仍然必须为返回类型创建自定义类,因为您无法从方法返回匿名类。通过使用
ToList()
扩展方法,可以避免声明和分配列表:

public static List<CustomViewType> GetJoinList()
{
    return (from c in customers
            join o in orders on o.customerid equals c.customerid
            select new CustomViewType { CustomerID = c.CustomerId, OrderDate = o.OrderDate}).ToList();
}
publicstaticlist GetJoinList()
{
退货(客户中的c)
在o.customerid等于c.customerid的订单中加入o
选择新的CustomViewType{CustomerID=c.CustomerID,OrderDate=o.OrderDate});
}

您可以返回匿名类型的列表。。。你只是不能用强类型的方式来实现。那么如何将匿名类型列表从DAL层传递到BLL层呢?