linq,即使我正在过滤条件,子句也返回所有内容

发布于 2025-01-30 19:51:19 字数 978 浏览 2 评论 0原文

我正在使用C#和Solrnet返回游戏玩家正在玩的游戏列表。

在我的C#代码中,我正在尝试返回Player History的数据,其中Isplaying是正确的。

该数据库具有一个适用于iSplaying的玩家的表(false forse,1,为true 1)。

这是我的代码:

var nodes = GetGamerNodes().Select(MapNode);
    Solr.AddRange(nodes);
    Solr.Commit();

private static SearchNodes MapNode(GameList node)
{
    return new SearchNodes {
        Id = node.Id.ToString(),
        GameTitle = node.Title,
        Story = node.Story,
        Published = node.Game.Published,
        PlayerHistory= node.Players.Where(e => e.Player.Current.IsPlaying).Select(e => e.Player.Name).ToArray()
    };
}

Player HistoryiCollection

在我的模型中,iSplaying是这样定义的:

public> public virtual virtual virtual bool iSplay {get;放; }

但是它正在返回player History全部数据的数据,而不管iSplaying的值如何。

我做错了吗?

谢谢!

I am using c# and SolrNet to return a list of games that gamers are playing.

In my c# code, I am trying to return data for PlayerHistory, where IsPlaying is true.

The database has a table for Players with a bit column (0 for false, 1 for true) for IsPlaying.

Here is my code:

var nodes = GetGamerNodes().Select(MapNode);
    Solr.AddRange(nodes);
    Solr.Commit();

private static SearchNodes MapNode(GameList node)
{
    return new SearchNodes {
        Id = node.Id.ToString(),
        GameTitle = node.Title,
        Story = node.Story,
        Published = node.Game.Published,
        PlayerHistory= node.Players.Where(e => e.Player.Current.IsPlaying).Select(e => e.Player.Name).ToArray()
    };
}

PlayerHistory is an ICollection

In my model, IsPlaying is defined like this:

public virtual bool IsPlaying { get; set; }

But it is returning PlayerHistory data for everything regardless of the value of IsPlaying.

Am I doing something wrong?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏至、离别 2025-02-06 19:51:19

这是一个小技巧,有时对我有帮助。

对我有用的是做一个这样的临时谓词:

bool debugGetIsPlayerPlaying(Player player)
{
    return player.Current.IsPlaying;
}

然后,当您进行此替换时...

private static SearchNodes MapNode(GameList node)
{
    return new SearchNodes
    {
        Id = node.Id.ToString(),
        GameTitle = node.Title,
        Story = node.Story,
        Published = node.Game.Published,
        PlayerHistory = node.Players.Where(e => debugGetIsPlayerPlaying(e.Player)).Select(e => e.Player.Name).ToArray()
    };            
}

...它为您提供了可以设置断点并逐步进行的东西,以帮助您确定失败的LINQ中发生的事情询问。希望这很有帮助!

Here's a little trick that has helped me at times like these.

What works for me is to make a temporary predicate like this:

bool debugGetIsPlayerPlaying(Player player)
{
    return player.Current.IsPlaying;
}

and then when you do this replacement...

private static SearchNodes MapNode(GameList node)
{
    return new SearchNodes
    {
        Id = node.Id.ToString(),
        GameTitle = node.Title,
        Story = node.Story,
        Published = node.Game.Published,
        PlayerHistory = node.Players.Where(e => debugGetIsPlayerPlaying(e.Player)).Select(e => e.Player.Name).ToArray()
    };            
}

... it gives you something you can set breakpoints on and step through to help you determine exactly what's going on in the failing Linq query. Hope this is helpful!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文