.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Sandeep Singh
Mayuri
stevemarkayden
kumarfurima
Preethi

Home >> Forum >> LINQ >> Post New QuestionBookmark and Share Subscribe to Forum

Class Hierarchy outpot using LiNQ

Posted By: Santosh     Posted Date: February 21, 2016    Points:5   Category :LINQ
Hi,
i need to bind relational data from sqlserver table into class hierarchy.
providing below example for more clarification.

tbl_Company
Company_ID Com_Name
1 Com1
2 Com2

tbl_Employee
Employee_Id Emp_Name Company_Id
1 Emp1 1
2 Emp2 2
3 Emp2 1

tbl_Invoice
Invoice_Id Invoice_Name Employee_Id
1 Invoice1 1
2 Invoice2 1
3 Invoice3 2

below are just add values into class using loop(Just for reference)
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("INV " + i.ToString(), i = i++);
Invoice empCou1 = new Invoice("INV2 " + i.ToString(), i = i++);
emp1.EmployeeCou.Add(empCou);
emp1.EmployeeCou.Add(empCou1);
emp2.EmployeeCou.Add(empCou1);
company.Employees.Add(emp1);
companies.Add(company);
}

how can i achieve the above scenario from sqlserver using LINQ(company class should contain hierarchical data based on foreign key relation)


Thanks

Responses

No response found. Be the first to respond this post
Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend