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