Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am very new to Entity Framework 4 and i tried populating a TreeView as shown in the figure. But i am getting errors. My lines of code is given.

TreeView

23-June-2013
|--Jaan
|--Prity
24-June-2013
|--Rahul
|--Rajiv



C#
 private void PopulateTreeView()
    {
using (var context = new DiagnosoftContext())
        {
            var q = (from i in context.Patients
                     group i by i.Date into grpDate
                     select grpDate);


foreach (var item in q)
            {
                TreeNode nodes = new TreeNode(q.ToString());    //Create root node first
                TreeNode tn = item as TreeNode;

                var childNodes = q;         //Next sub-query to be write
                foreach (var child in childNodes)        //Adding child nodes to root node if it have any
                {
                    TreeNode childNode = new TreeNode(q.ToString());
                    nodes.Nodes.Add(childNode);
                }
                treePatient.Nodes.Add(nodes);           //At the last add the root node with child nodes to treeview

            }

        }
}


public class Patient
{      
        public int PatientId { get; set; }
        public int RegisteredNo { get; set; }
        public DateTime Date { get; set; }
        public string PatientName { get; set; }
        public int Age { get; set; }
        public int Sex { get; set; }
}


Please help me. Thank you in advance.
Posted
Comments
[no name] 23-Jun-13 16:39pm    
And the errors you are getting are what?
apurba001 23-Jun-13 16:46pm    
Error is "EntityCommandExecutionException" at childNodes.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900