0

I'm working with visual studio 2010 and I have this list:

    List<SPFieldUserValue> directeursDelegues = (from SPListItem agence in webSite.Lists[agenceGuid].Items
                                         select (SPFieldUserValue)delegueField.GetFieldValue(agence["Directeur_x0020_D_x00e9_l_x00e9_"].ToString())
                                         ).Distinct().ToList();

I'm trying to get distinct values from this list. But it doesn't seem to work. Do you know how to do it?

EDIT:

I've found the answer:

    List<SPFieldUserValue> directeursDelegues = (from SPListItem agence in webSite.Lists[agenceGuid].Items//agence list
                                                                             select (SPFieldUserValue)delegueField.GetFieldValue(agence["Directeur_x0020_D_x00e9_l_x00e9_"].ToString())
                                                                             ).GroupBy(x => x.User.ID).Select(group => group.First()).ToList();

I don't know if it is the best way but it works fine.

1
  • If its working fine, go for this.
    – Aanchal
    Jun 23, 2014 at 14:10

1 Answer 1

0

CAML query schema for Sharepoint doesn't contain distinct still, so there is not Distinct operation in CAML Queries.

However you may group results in CAML (using GroupBy element) - it will produce groups for distinct values of the field by which you will perform grouping. So this is only otption for you to get uniques values.

CAML query on Sharepoint List without duplicates

http://social.technet.microsoft.com/Forums/sharepoint/en-US/c2bbcf13-a53d-4755-87dd-871a51840a4d/select-distinct-in-caml-query-for-list

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.