使用LINQ将字符串值与对象递归列表进行比较 [英] Using LINQ to compare a string value with an object recursive list

查看:123
本文介绍了使用LINQ将字符串值与对象递归列表进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个名为权限"的查询,其中包含一个从XML文件中提取的对象列表.

在下面找到xml结构的示例:

Hi guys,

I have a query called permissions which contains an object list that I extracted from a XML file.

Find below an example of the xml structure:

<permission id="1">
  <permission id="1.1" />
  <permission id="1.2">
    <permission id="1.2.1" />
    <permission id="1.2.2" />
  </permission>
  <permission id="1.3" />
</permission>


如我们所见,我必须创建一个递归查询才能提取整个数据.现在,我需要使用该列表与另一个查询中的特定值进行比较.例如:


As we can see I have to create a recursive query in order to extract the entire data. Now, I need to use that list to compare with a specific value inside another query. For example:

var query = (from x in items.Elements()
            where (permissions.Any(i => i.Id == x.Attribute("id").Value))
            select ......


问题是Any<> operator只是将值与列表中的第一级节点进行比较.

有谁知道解决这个问题的另一种方法?我的意思是,如何获取/比较整棵树?


The problem is Any<> operator just compare the value with the first level nodes of my list.

Does anyone know a different approach to solve this problem? I mean, how to get/compare the entire tree?

Thanks in advance!

推荐答案

有一个非常相似的问题
There''s very similar issue right here.You could follow thread suggestions for your problem too.


这篇关于使用LINQ将字符串值与对象递归列表进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆