c# - linq left outer join object reference not set to an instance of an object -
i using left outer join in query below. variable fgi coming null so line after in giving object reference error. how can solve it?.
var = (from e1 in _db.features.tolist() e1.int_parentid==0 && e1.bit_ismodule == true & e1.bit_showinmenu == true && e1.bit_activate == true join e2 in _db.organizationmodules on e1.int_featureid equals e2.int_featureid fg fgi in fg.defaultifempty() fgi.bit_organizationmoduleactivedeactive != false && fgi.int_organizationid == sepiacms.models.security.authorization.organizationid // object reference not set instance of object orderby e1.int_featuressortid ascending, e1.int_featureid descending select new featureviewmodel { featureid = e1.int_featureid, featurename = e1.vcr_featuresname, classes = path == e1.vcr_linkname ? "<li class=active>" + html.actionlink(e1.vcr_featuresname, e1.vcr_linkname.substring(e1.vcr_linkname.indexof('/') + 1), e1.vcr_linkname.substring(0, e1.vcr_linkname.indexof('/')), new { area = string.isnullorempty(e1.vcr_area) == true ? "" : e1.vcr_area }, new { @class = e1.vcr_cssclass }) + "</li>" : "<li>" + html.actionlink(e1.vcr_featuresname, e1.vcr_linkname.substring(e1.vcr_linkname.indexof('/') + 1), e1.vcr_linkname.substring(0, e1.vcr_linkname.indexof('/')), new { area = string.isnullorempty(e1.vcr_area) == true ? "" : e1.vcr_area }, new { @class = e1.vcr_cssclass }) + "</li>" }).tolist();
since doing left join guess want include null values. add
where fgi == null || (....) or if don't want null values change query inner join.
Comments
Post a Comment