Search code examples
c#wcfxamlwcf-data-services

DataServiceCollection to a String


I have dataServiceCollection and want to pull out some info from it and put it into a string.

    private DataServiceCollection<P.Groups> groups;
    public DataServiceCollection<P.Groups> Groups()
    {
        if (groups == null)
        {
            Uri pRoot = new Uri("http://localhost:19297/WcfDataService1.svc/");
            P.Entities data = new P.Entities(pRoot);

            var query = (DataServiceQuery<P.Groups>)data.GroupsSet;
            groups = new DataServiceCollection<P.Groups>();
            groups.LoadAsync(query);  
        }
        return groups;
    }


    protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
    {


        var g = Groups();
        this.DefaultViewModel["Groups"] = g;
    }

I can bind this to my xaml page with no problem, but I want to put "g" to a string.


Solution

  • May be just using linq, something like

    g.Items.Aggregate((i, j) => i + delimeter + j)
    

    from this post: Concat all strings inside a List<string> using LINQ