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...

4
  • 2
    Your question has nothing to do with MVC. Its all LINQ. Commented Mar 30, 2012 at 5:44
  • 1
    Check this question: stackoverflow.com/questions/5207382/… Commented Mar 30, 2012 at 6:08
  • 1
    Do you know what a JOIN is? There is also a join keyword for linq. Commented Mar 30, 2012 at 9:05
  • 1
    Stan, with linq please also use tags for linq provider (linq to sql, entity framework, ...) Commented Mar 31, 2012 at 19:28

1 Answer 1

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};
Sign up to request clarification or add additional context in comments.

1 Comment

You can also use? You should. The first example is a Cartesian product.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.