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 8635983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:06:36+00:00 2026-06-12T10:06:36+00:00

I thought its possible to save multiple linq queries from a loop in a

  • 0

I thought its possible to save multiple linq queries from a loop in a single variable ?

public ActionResult Index()
    {
        string ActiveUserId = (string)Session["ActiveUserGuid"];
        Guid MyGuid = new Guid(ActiveUserId);

        var queryRoots = from r in db.Roots
                         where r.UserId == MyGuid
                         select r.TaskId;

//Here is the questionable Part
        foreach (var i in queryRoots)
        {             
            var queryAllTasks = from t in db.Tasks
                                join b in db.Trees on t.TaskId equals b.ChildId
                                where b.TaskId == i
                                select t;
            tasksForView.Add(queryAllTasks); <---????? obviously doesnt work
        };

        return View(queryAllTasks);
    }

public class Root
{
    public int RootId { get; set; }

    public Guid UserId { get; set; }
    public User User { get; set; }  //navigation Property

    public int TaskId { get; set; } // composite key
    public int ChildId { get; set; }
    public Tree Tree { get; set; } //navigation Property
}

public class Tree
{
    public int TaskId { get; set; }
    public int ChildId { get; set; }
    public int Length { get; set; } //Path length

    public virtual ICollection<Root> Roots { get; set; }

}

In case you are wondering what its supposed to do. I want to query several subtrees from a hierarchical transitiv closure table and return them to a view.

I know my code is not close to working and I just tried very simple solutions!
I guess a different way to do the query would get rid of the problem all together

  • 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-06-12T10:06:37+00:00Added an answer on June 12, 2026 at 10:06 am

    Use Contains on your integer list:

    var tasks = 
        from t in db.Tasks
        join b in db.Trees on t.TaskId equals b.ChildId
        where queryRoots.Contains(b.TaskId)
        select t;
    
    return View(tasks);
    

    or do it all in one query:

    var tasks = 
        from t in db.Tasks
        join b in db.Trees on t.TaskId equals b.ChildId
        join r in db.Roots on r.TaskId equals b.TaskId
        where r.UserId == MyGuid
        select t;
    
    return View(tasks);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It's possible to call .NET from MATLAB, so I thought I would try to
Hello folks is it possible to find a controll by its name via Linq?
I thought there was a way to quickly ask a NSSet to poll its
I always thought that internal class has access to all data in its external
I'm making an app where I need to save the text in multiple views
I use session-per-call to save a detached collection with possible adds/updates (so includes some
I recently heard of Jikes RVM and i was trying to go though its
I know WF designer has re-hosting capability. Since it's WPF-based, I thought it might
I use this class to parse a .css file. https://github.com/sabberworm/PHP-CSS-Parser I thought it's easy
OK so I thought this would be pretty simple but it's tripping me up..

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.