[RESOLVED]Query has definitely results in but error :value null


  I have this query that is working just  fine ,

But when I try this query I’m getting  a non-logical Error and I can understand why

  public PartialViewResult _allparsha()
            var ParshasList = db.Parshas.Include(s => s.Subjects); 
            return PartialView(ParshasList);
        }//Result Ok.

Running this :

public PartialViewResult _allparsha()
          var ParshasList = db.Parshas.Where(s => s.Subjects.Any(la => la.languageID == 1)).ToList();
            return PartialView(ParshasList);
//Result : Error :

The error i’m getting is :

Line 86:                     @foreach (var item in hagim.OrderByDescending(n => n.NuParsha))
Line 87:                     {
Line 88:                         if (item.Subjects.Count() > 0)
Line 89:                         {
Line 90:                             <li class="active thumbnail">

my view model:

@model IEnumerable<Hagadol12_8.Models.Parsha>

if I have no results in my query (no items with the "languageID == 1" then I’m not getting any error in my view.

I think that this is from the useof  : Any() with IEnumerable but I have no idea how to use it differently 


      if (item.Subjects != null && item.Subjects.Count() > 0)


      if (item.Subjects != null && item.Subjects.Count() > 0)

Hello, thanks ,

Leave a Reply