我在 Asp.Net 4.0 C# - MVC-3 中工作。我有一个问题,不知道如何解决。我有4个表,想要使用 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
以下是我需要获取的字段..(使用LINQ查询)
那么,如何使用linq查询获取数据?
提前致谢...
答案 0 :(得分:3)
尝试以下示例:
(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
或者您也可以使用以下示例:
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};