简体   繁体   中英

How to compare inside linq query in a foreach loop

In this foreach loop, I want to find my model with this Condition you see. The problem is I can't compare b.GroupId and group.GroupId it says b.GroupId is null but the group.GroupId is not null I have traced it and it has a value of 1. This is my code

@foreach (var group in groups.Where(g => g.ParrentId == null))
{
    <div class="tab-pane active animated fadeInRight" id="tab_@group.GroupId">
    var blog = Model.First(b=>b.GroupId==group.GroupId);
}

my model

@model IEnumerable<DataLayer.Entities.Blog.Blog>

@inject Core.Services.Interfaces.IGroupServices _groupServices;
@{ 
List<DataLayer.Entities.Group.Group> groups = 
_groupServices.getAllGroups();}
 

在此处输入图片说明

as you see group.GroupId is 1 but 'a' is still 0 this is an example of my problem

but the group .GroupId is not null

But as you stated the issues is with b , not with group . So somewhere in your model there is GroupId with null. It is unclear how to fix that since there are no information about your Model. But maybe something like this will help:

Model.First(b=>b.GroupId!=null && b.GroupId==group.GroupId);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM