I'm trying to convert the next query with left joins in order to get a IList of one of my model objects.
This is the query:
select M.MilestoneID, MT.MilestoneTypeID, M.RCCAID
from Sourcing.MilestoneType MT
left join Sourcing.Milestone M on M.MilestoneTypeID = MT.MilestoneTypeID
where M.MilestoneID is null or (M.RCCAID = 1)
Output I get in SQL
MilestoneID | TypeID | RCCAID
------------+--------+--------
1 | 1 | 1
NULL | 1 | NULL
I have tried with this
var list = from mt in db.MilestoneType
join m in db.Milestone on mt.MilestoneTypeID equals m.MilestoneTypeID
where m.RCCAID == id || m.MilestoneID == 0
select new Milestone
{
MilestoneID = m.MilestoneID,
RCCAID = m.RCCAID,
MilestoneTypeID = mt.MilestoneTypeID
};
var list1 = db.MilestoneType.Join(db.Milestone,
mt => mt.MilestoneTypeID,
m => m.MilestoneTypeID,
(mt, m) => new Milestone()
{
MilestoneID = m.MilestoneID,
RCCAID = m.RCCAID,
MilestoneTypeID = mt.MilestoneTypeID
}).Where(a => a.RCCAID == id ||a.MilestoneID==0).ToList();
The first one does not work.
And I get this error in the second one:
The entity or complex type 'Model.Milestone' cannot be constructed in a LINQ to Entities query
I'm trying to get all the milestone per RCCA with all the milestone types even if a milestone type is not created yet.
I expect to get an IList<Milestone>
.