Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1094939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:02:46+00:00 2026-05-17T00:02:46+00:00

var nodes = (from n in db.Nodes join st in db.SessionTrackings on n.NodeID equals

  • 0
var nodes = (from n in db.Nodes
                 join st in db.SessionTrackings on n.NodeID equals st.NodeID
                 where st.UserID == userid && st.GroupID == groupid
                 select n);

IDictionary<int, bool> trackingData = new Dictionary<int, bool>();

foreach (Node n in nodes)
{
    trackingData.Add(new KeyValuePair<int, bool>(n.ID, true));
}

I keep getting a ‘that key was already added’ because there could be many SessionTrackings per Node, however I just want to get back all the Nodes that have at least 1 SessionTracking in existence for the NodeID but I don’t need to get the Nodes more than once. If there are 4000 SessionTrackings for a Node (say ID = 45) I still only one 1 instance of Node 45 in my IQueryable. How can I modify my query for this? Please don’t worry about why I need it in a Dictionary that’s just the way it is.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:02:47+00:00Added an answer on May 17, 2026 at 12:02 am

    You just need to tell the query engine that you only want distinct instances of your objects:

    var nodes = (from n in db.Nodes 
                 join st in db.SessionTrackings on n.NodeID equals st.NodeID 
                 where st.UserID == userid && st.GroupID == groupid 
                 select n).Distinct();
    
    IDictionary<int, bool> trackingData = nodes.ToDictionary(n => n.ID, n => true);
    

    If you don’t need the nodes query for anything else, you can combine the statements like this:

    IDictionary<int, bool> trackingData =
                (from n in db.Nodes 
                 join st in db.SessionTrackings on n.NodeID equals st.NodeID 
                 where st.UserID == userid && st.GroupID == groupid 
                 select n.Id)
                .Distinct()
                .ToDictionary(i => i, i => true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a d3 force-directed graph that contains a group of nodes: var node
I need to export my nodes like this: function recursive_simplify(node){ if(node.children){ for(var i =0;i<node.children.length;i++){
I'm trying to get all nodes from an XElement that actually has a value,
My goal is to remove all <[script]> nodes from a document fragment (leaving the
So Im trying to extract nodes from my database (by going through it recursively)
jqGrid tree nodes are read from server using json data. Click in node reads
I'm using this code: /** * Get Text Nodes from an Element * Returns
I have two arrays var nodes = new Array(alpha,beta,omega); var childnodes = new Array(one,two,three);
I have a method GetSelectedServices() which returns Selected Nodes from a Tree List, Expecting
Suppose I have an array of objects like this: var nodes = [{size:8,name:myName},{size:10,name:otherName},{size:11,name:userName}]; How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.