我目前拥有以下直径, 它运行并获得两个强烈键入对象( DAL. Driver 和 DAL. Licence ) 。 但我要将结果投到一个包含 BLL. Driver 和 BLL. Licence 对象的单一驱动ODSJoined 对象 。
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 });
}
}
对于连接到一个类对象的查询,I会这样做:
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();
然而,它却不起作用。我怎么能这样做呢? 最终,我该如何用一份清单,其中每个清单都包含一个 BLL. Driver 和 BLL. Licence 对象的例子?
Thanks, Richard