0
Reply

how to bind relational table data into class hierarchy

santosh behera

santosh behera

Feb 22 2016 9:59 AM
411
<html>
Hi,
i need to bind relational table from sqlserver into class hierarchy.
below are the tables i want to add into class hierarchy.
tbl_Company
Company_ID Company_Name
1 Company 1
2 Company 2
tbl_Employee
Employee_Id Employee_Name Company_Id
1 Employee1 1
2 Employee2 2
3 Employee3 1
tbl_Invoice
Invoice_Id Invoice_Name Employee_Id
1 Invoice1 1
2 Invoice2 1
3 Invoice3 2
tbl_Company.Company_Id foreigh key with tbl_Employee.Company_Id
tbl_Employee.Employee_id = tbl_Invoice.Employee_Id
i want to bind above table into list of classes.
means tbl_company will contain respected employee and employee will contain respected Invoice based on foreign key relation
Company1
-----Employee1
---------Invoice1
---------Invoice2
-----Employee3
Company2
-----Employee2
----------Invoice3
 
i have manually added some value below using loop, just to give a clear idea.
for (int i = 0; i < 10; i++)
{
Company company = new Company("CN " + i.ToString());
Employee emp1 = new Employee("Employee1 " + i.ToString(), i = i++);
Employee emp2 = new Employee("Employee2 " + i.ToString(), i = i++);
Invoice empCou = new Invoice("Invoice1 " + i.ToString(), i = i++);
Invoice empCou1 = new Invoice("Ivoice2 " + i.ToString(), i = i++);
emp1.EmployeeCou.Add(empCou);
emp1.EmployeeCou.Add(empCou1);
emp2.EmployeeCou.Add(empCou1);
company.Employees.Add(emp1);
companies.Add(company);
}
Thanks