locked
How to group by Multiple fields value returned by function in linq? RRS feed

  • General discussion

  • Error -Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.

                                            

        async private void DefaultQuery()
            {

                  ContactStore  store = await ContactStore.CreateOrOpenAsync(
                    ContactStoreSystemAccessMode.ReadWrite,
                    ContactStoreApplicationAccessMode.ReadOnly);

                    ContactQueryResult KK = null;
                    KK = store.CreateContactQuery();

                    IReadOnlyList<StoredContact> contacts = null;
                    contacts = await KK.GetContactsAsync();


                    var Emailquery1 = contacts.GroupBy(x =>new{ getData(x,1)["Email"].ToString(),getData(x,2)["MobileTelephone"].ToString()})
                        .Where(g => g.Count() > 1)
                            .Select(y => new { Element = y.Key.ToString(), Counter = Convert.ToInt32(y.Count()) })
                             .ToList();      

            } 

      private IDictionary<string, object> getData(StoredContact x, int Prop)
            {
                IDictionary<string, object> result = null;        
                Task<IDictionary<string, object>> properites = x.GetPropertiesAsync().AsTask();          
                if (properites != null)
                    result = (IDictionary<string, object>)properites.Result;
                if (!result.ContainsKey("Email") && Prop == 1)
                    result.Add("Email", "");
                if (!result.ContainsKey("MobileTelephone") && Prop == 2)
                    result.Add("MobileTelephone", "");
                return result;
            }

    Here I want to group by values coming from getData(StoreContact x) function.

    Thursday, September 10, 2015 6:04 AM