【问题标题】:How to select Distinct names from a xml database using LINQ?如何使用 LINQ 从 xml 数据库中选择不同的名称?
【发布时间】:2013-12-16 03:20:48
【问题描述】:

我正在尝试这个查询来获取所有城市的

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

所以它返回所有城市,包括重复的,但我只想获得不同的城市,即只重复城市,那么如何实现呢?

【问题讨论】:

    标签: c# sql xml linq windows-phone-7


    【解决方案1】:

    使用Distinct Extension Method

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

    【讨论】:

    • 再明显不过了,嗯?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-18
    • 1970-01-01
    • 2020-03-09
    • 2020-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多