I want to convert this sql query to LINQ
left join @categories oc
on OC.course_id = t.course_id
and isnull( t.offlinecategory_id,-1) = isnull(oc.offlinecategory_id,-1)
I tried in this way but results are not same in sql and LINQ
join drv in categories
on new { a1 = t?.CourseID ?? 0, a2 = (t?.OfflineCategoryID ?? -1) }
equals new { a1 = drv.CourseId, a2 = drv.OfflineCategoryId ?? -1 } into cgroup
from oc in cgroup.DefaultIfEmpty()
Courseentity should have aCategoryorCategoriesproperty. If you load aCourseobject then EF itself will generate the JOIN that also loads the relatedCategory.ISNULLis quite simply a bug that prevents the use of indexes. NULLs aren't 0s in any database. Either useOR (t.offlinecategory_id is null AND offlinecategory_id is null)or store a default value in that field. If you care about performance the SQL query itself needs to changeISNULLnot NULL. Indexes are generated based on the stored values and can't be used to speed up filtering on function results. You can create a computed column with the function result and index it but SQL Server won't use it automatically to accelerate functions. In PostgreSQL you can create indexes on expressions, which can be used