If someone wants to know how I did this, I did not use the null coalesce operator ... It was even easier. Maybe I didnβt explain myself, but I had to say that if the value is null, then I want to include this result. Check this.
possibleVendors = (from vndMapping in db.COMPANIES_VND_MAPPINGS join v in db.COMPANIES_CMP_COMPANIES on vndMapping.VENDOR_ID equals v.COMPANY_ID where !(from ex in db.COMPANIES_VND_MAPPINGS where (ex.OEM_ID == oemId || ex.OEM_ID == null) && (ex.MODEL_ID == modelId || ex.MODEL_ID == null) && (ex.MODALITY_ID == modalityId || ex.MODALITY_ID == null) && (ex.CLASS_ID == productTypeId || ex.CLASS_ID == null) && ex.EXCLUDE.ToUpper().Equals("Y") select ex.VENDOR_ID).Contains(vndMapping.VENDOR_ID) && (vndMapping.OEM_ID == oemId || vndMapping.OEM_ID == null) && (vndMapping.MODEL_ID == modelId || vndMapping.MODEL_ID == null) && (vndMapping.MODALITY_ID == modalityId || vndMapping.MODALITY_ID == null) && (vndMapping.CLASS_ID == productTypeId || vndMapping.CLASS_ID == null) select new { vndMapping.VENDOR_ID, v.COMPANY_NAME }).Distinct().OrderBy(x => x.VENDOR_ID).ToDictionary(x => x.VENDOR_ID, x => x.COMPANY_NAME);
Now keep in mind - I had a few limitations in that I did not design the business logic (obviously) or the database. Someone might have a better way to do this, if you had full control of everything, this seems to work.
source share