简体   繁体   English

如何使用LINQ从xml数据库中选择唯一名称?

[英]How to select Distinct names from a xml database using LINQ?

i am trying this query to get all the city's 我正在尝试此查询以获取所有城市的

var queryAllCustomers = from cust in loadedCustomData.Descendants("record")
                                select (string)cust.Element("City") ;

so it returns all city's including repeated, but i only want to get distinct city ie to repeat only ones so how to achieve that? 所以它返回所有城市,包括重复的城市,但是我只想获得与众不同的城市,即仅重复一个城市,那么如何实现呢?

Use Distinct Extension Method 使用不同的扩展方法

var queryAllCustomers = (from cust in loadedCustomData.Descendants("record")
                            select (string)cust.Element("City")).Distinct();

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

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