简体   繁体   English

如何在foreach循环中比较内部linq查询

[英]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.在这个 foreach 循环中,我想用你看到的这个 Condition 找到我的模型。 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问题是我不能比较b.GroupIdgroup.GroupId它说b.GroupId为空,但group.GroupId IS NOT NULL我已经跟踪它,它具有1的值。这是我的代码

@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正如你所看到的 group.GroupId 是 1 但 'a' 仍然是 0 这是我的问题的一个例子

but the group .GroupId is not null.GroupId 不为空

But as you stated the issues is with b , not with group .但是正如您所说,问题出在b 上,而不是group 上 So somewhere in your model there is GroupId with null.所以在你的模型中的某个地方有 GroupId 为空。 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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