linq left outer join object reference not set to an instance of an object

i am using left outer join in this query below. the variable fgi is coming null so so the line after that in where it giving object reference error. how can solve it?.

 var a = (from e1 in _db.Features.ToList()                                             
                                         where 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 into fg
                                         from fgi in fg.DefaultIfEmpty()
                                         where fgi.bit_OrganizationModuleActiveDeactive != false && fgi.int_OrganizationId == SepiaCMS.Models.Security.Authorization.OrganizationID   // object reference not set to instance of an 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();

Answers


Since you are doing a left join i guess you want to include the null values. Just add

where fgi == null || (....)

Or if you don't want the null values just change the query to an inner join.


Need Your Help

boolean function not working

c++ arrays function boolean

I'm wondering if the logic is right for this. The function gets paased an array of lets say 1,2,3,4,5 through compcards[] and also a number a user would input such as 4. however if the user guessed...

Prevent access to php pages

php file .htaccess

Ok, so I have set the .htaccess like so:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.