c# - Group and Filter Collection by another Collection in LINQ -


I have a large set of data in this form:

  public class permission {Public string url {get; Set; } Public string user {get; Set; } Public string permission level {get; Set; }}   

and list & lt; String & gt; As is a second collection. SiteCollections . Sample data:

  http: // domain / project / 1 http: // domain / project / 2 http: // domain / project / 3 http: // domain / project / 4 http : // domain / project / 5   

Now my goal is to list this list; Permission & gt; Permissions by users . So it gives me

  var filteredAndGrouped = data.Where (u = & gt; u.User == @ "domain \ username")   

After this I want to add this result to the group from the part of its URL. Started with a URL of SiteCollections, if each permissions URL is started with D. == @ " Domain \ user ") .GroupBy (d = & gt; SiteCollections.Any (sc = & gt; sc.StartsWith (d.Url)))

This group is right with a key / Are incorrect and are the only URL which is excatly in the group with the key truth in the form of list SiteCollections What do I need to do in grouping with the url in the list SiteCollections and the permissions url must be started with the key of the group. To do this, there is no need to be equal.

Finally, I need a result in this form:

  key: http: // domain / project / 1 permission 1 (url: http: // domain / Project / 1 / xyz / xyz) Permission 3 (url: http: // domain / project / 1 / xyzz / xqeqyz) Permission 7 (url: http: // domain / project / 1 / xadadyz / xadadyz) key: http: // domain / project / 2 permission 2 (url: http: // domain / project / 2 / adyz / xdyz) Permission 4 (url: http: // domain / project / 2 / a2dyz / xdyz) Permission 21 (URL: http: // domain / project / 2 / a22dyz / xdyz) key: http: // domain / project / 3 permission 22 (url: ...    

  var grouped = appendix Select .groupBy (x = & gt; SiteCollections.FirstOrDefault (u = & gt; x URL. Start (U)). Select (x => New {Key = X.Keys, Permissions = X. ToArray ( )}) .ORR ();   

The result may be in the null key, that means the URL SiteCollections . is not present in.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -