1

I am working in Asp.Net 4.0 C#-- MVC-3. I have one problem and don't know how to solve. I have 4 tables and want to fetch data from that tables with LINQ.

TABLES

1) Project_Master

    Field Names :   

    project_id (pk)
    project_name
    company_id (FK with company_master)
    company_category_id (FK with Company_Category_master)
    project_status_id (FK with Project_Status_Master)

2)Company_Master

   Field Names :

   company_id
   company_name
   company_category_id (FK with Company_Category_Master)

3) Company_Category_Master

   Field Names :

   Company_Category_Id
   Company_Category_Name

4) Project_Status_Master

   Field Name :

   Project_Status_Id
   Project_Status_Name

Below are the fields I need to fetch..(using LINQ Query)

  1. Company_Name
  2. Total completed project using status id(1)=complete (where staus 1 means completed)
  3. Total Project
  4. Company_category_name

So, how can I fetch data with linq query??

Thanks in advance...

Stan
  • 189
  • 8
  • 19
  • 2
    Your question has nothing to do with MVC. Its all LINQ. – RG-3 Mar 30 '12 at 05:44
  • 1
    Check this question: http://stackoverflow.com/questions/5207382/get-data-from-two-tablesjoin-with-linq-and-return-result-into-view –  Mar 30 '12 at 06:08
  • 1
    Do you know what a [JOIN](http://en.wikipedia.org/wiki/Join_(SQL)) is? There is also a `join` keyword for linq. – Stephan Mar 30 '12 at 09:05
  • 1
    Stan, with linq please also use tags for linq provider (linq to sql, entity framework, ...) – Gert Arnold Mar 31 '12 at 19:28

1 Answers1

3

Try the below example:

(From lse In Me.Leases, nty In Me.Entities, psg In Me.ProductionStages, lsg In LeaseStages _
        Where lse.LeaseName = leaseName _
        Select lse, lsg, nty, psg).Single

or you can use below example too:

var employeesQuery = from populationTable in db.Populations
join personTable in db.Persons on populationTable.Guid equals personTable.PopulationGuid
join employeeTable in db.Employees on personTable.Guid equals employeeTable.PersonGuid
select new { populationTable, personTable, employeeTable};
pjumble
  • 16,880
  • 6
  • 43
  • 51
SeeSharp
  • 179
  • 1
  • 4
  • 12