I currently have the following linq which runs and gets two strongly typed objects (DAL.Driver and DAL.Licence). However I want to cast the result out in to the a single DriverODSJoined object that contains a BLL.Driver and BLL.Licence object.
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 });
}
}
For linked queries in to one class object i would do this:
query.Select(a => new BLL.Driver.Driver()
{
id = a.Driver.id
etc
}).ToList();
So to populate a list of DriverODSJoined I thought I would do something like this:
query.Select(a => new BLL.Driver.DriverODSJoined()
{
driver.id = a.Driver.id,
licence.id = t2.id
}).ToList();
However it doesn’t work. How can I do this to end up with a List each of which contains an instance of a BLL.Driver and BLL.Licence object?
Thanks,
Richard
I figured it out shortly afterwards and of course I had to instantiate each object within the containing object before assigning values to their member variables. So here is the example: