c# - LEFT JOIN or RIGHT JOIN using LINQ Entity-Framework -
trying joining using linq. should use ? left join or right join?
applicant table profile table applicant_id|profile_id|applicant_name| |profile_id|applicant_name 1 | null | ray heavens | | 1 | mark lapid 2 | null | ben tulfo | | 2 | super man 3 | 1 | null | | 3 | brandon knight 4 | 2 | null | | 5 | 3 | null | | desired output: applicant_id | applicant_name 1 | ray heavens 2 | ben tulfo 3 | mark lapid 4 | superman 5 | brandon knight
this code in controller:
var applicantlist = (from in context.profiles join app in context.applicants on a.profile_id equals app.profile_id output j in output.defaultifempty(new applicant()) select j ).take(1000).asenumerable(); applicantdata = applicantlist.asqueryable().orderby(v => v.applicant_id).tolist(); if (applicantdata.any()) { cache.set("applicants", applicantdata, 30); } } return applicantdata; }
i hope can recommend me use or do. thank in advance.
updated error: you need create new class required properties , return it.
var applicantlist = (from app in context.applicants join in context.profiles on app.profile_id equals a.profile_id output j in output.defaultifempty() select new { applicant_id = app.applicant_id, applicant_name = (j == null ? app.applicant_name : j.applicant_name) }).take(1000).asenumerable();
Comments
Post a Comment