0

I have this data :

public class MetaLink
{
 public long LinkNumbering { get; set; }
 public long TargetPageId { get; set; }
 public string TargetUrl { get; set; }
 public LinkType LinkOfType { get; set; }
}
public static ConcurrentDictionary<int, List<MetaLink>> Links = new ConcurrentDictionary<int, List<MetaLink>>();

How can I obtain all index of MetaLink object in the list dictionnary values and the correspondig dictionnary key with TargetUrl property == "Some value"

Perhaps is possible with Linq, but I don't find it. I do this :

var someLinks = Links.Values.Where(kvp => kvp.Any(ml => ml.TargetUrl == "Some value"));

But I can't get the correspondig dictionnary int key

asked Oct 5, 2015 at 15:51
1
  • Your run-on sentence is really hard to parse. It would be much easier to help if you if you'd give a concrete example with sample input and expected output - ideally with what you've tried so far, too. Commented Oct 5, 2015 at 15:54

2 Answers 2

1

You're close - you want

var someLinks = Links.Where(kvp => kvp.Value.Any(ml => ml.TargetUrl == "Some value")) 
 // all key.value pairs where the Value contains the target URL
 .Select(kvp => kvp.Key); //keys for those values
answered Oct 5, 2015 at 16:29
Sign up to request clarification or add additional context in comments.

Comments

0

Give a try on this. Haven't compiled.

var key = Links.Where(kvp => kvp.Value.Any(ml => ml.TargetUrl == "Some value")).Select(x => x.Key).SingleOrDefault();
answered Oct 5, 2015 at 16:23

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.