我目前有以下 linq,它运行并获取两个强类型对象(DAL.Driver 和 DAL.Licence)。但是,我想将结果转换为包含 BLL.Driver 和 BLL.Licence 对象的单个 DriverODSJoined 对象。
public class DriverODSJoined
{
public BLL.Driver driver { get; set; }
public BLL.Licence licence { get; set; }
public static void GetData()
{
DAL.DriverDataContext dataContext = new DAL.DriverDataContext();
var query = (from d in dataContext.drivers
join c in dataContext.licences on d.licence_id equals c.id into t1
from t2 in t1.DefaultIfEmpty()
select new { Driver = d, Licence = t2 });
}
}
对于一个类对象的链接查询,我会这样做:
query.Select(a => new BLL.Driver.Driver()
{
id = a.Driver.id
etc
}).ToList();
因此,要填充 DriverODSJoined 列表,我想我会做这样的事情:
query.Select(a => new BLL.Driver.DriverODSJoined()
{
driver.id = a.Driver.id,
licence.id = t2.id
}).ToList();
但是它不起作用。我该如何做才能得到一个 List ,每个 List 都包含一个 BLL.Driver 和 BLL.Licence 对象的实例?
谢谢,理查德