To replicate this logic in LINQ, you should: Use join with new { } to define composite keys. Use null-coalescing operators (??) to apply -1 as a default value for nullable fields. Use DefaultIfEmpty() to handle the left join behavior.
var query = from t in mainTable join drv in categories on new { CourseID = t?.CourseID ?? 0, OfflineCategoryID = t?.OfflineCategoryID ?? -1 } equals new { CourseID = drv.CourseID, OfflineCategoryID = drv.OfflineCategoryID ?? -1 } into cgroup from oc in cgroup.DefaultIfEmpty() // This handles the LEFT JOIN select new { // Select fields from mainTable (t) and the joined table (oc) t.CourseID, t.OfflineCategoryID, CategoryCourseID = oc?.CourseID, // This will be null if there's no match CategoryOfflineCategoryID = oc?.OfflineCategoryID };