SELECT PART_TYPE.PART_TYPE_ID,
PART_TYPE.PART_TYPE_NAME,
PART_AVAILABILITY.DATE_REF,
PART_TYPE.VEHICLE_ID,
PART_AVAILABILITY.AVAIL_COUNT
FROM PART_AVAILABILITY
RIGHT JOIN PART_TYPE
ON PART_AVAILABILITY.PART_TYPE_ID = PART_TYPE.PART_TYPE_ID
AND PART_AVAILABILITY.VEHICLE_ID = PART_TYPE.VEHICLE_ID
where PART_TYPE.VEHICLE_ID = 366
PART_TYPE_ID and VEHICLE_ID are Primary Key in PART_TYPE table.
VEHICLE_ID is a Foreign Key from VEHICLE table.
DATE_REF, PART_TYPE_ID and VEHICLE_ID are Primary Key in PART_AVAILABILITY table.
VEHICLE_ID and PART_TYPE_ID are Foreign Key from PART_TYPE table.
Above query gave below output.
PART_TYPE_ID PART_TYPE_NAME DATE_REF VEHICLE_ID AVAIL_COUNT
5 A1 2013-06-20 00:00:00.000 366 1
6 B1 2013-06-20 00:00:00.000 366 2
7 C1 2013-06-20 00:00:00.000 366 1
8 D1 NULL 366 NULL
9 E1 NULL 366 NULL
16 F1 2013-06-20 00:00:00.000 366 1
This my linq query for above sql query.
var vehiclePartType = from pa in context.PART_AVAILABILITY
join pt in context.PART_TYPE
on pa.PART_TYPE_ID equals pt.PART_TYPE_ID into joined
from j in joined.DefaultIfEmpty()
where j.VEHICLE_ID == 366
select new
{
PART_TYPE = j,
PART_AVAILABILITY = pa
};
But linq query gave below output.
PART_TYPE_ID PART_TYPE_NAME DATE_REF VEHICLE_ID AVAIL_COUNT
5 A1 2013-06-20 00:00:00.000 366 1
6 B1 2013-06-20 00:00:00.000 366 2
7 C1 2013-06-20 00:00:00.000 366 1
16 F1 2013-06-20 00:00:00.000 366 1
NULL records are missing.
How can i solve this ?