Multiple Join Query
-
Hi, I have a smallish database that is used to record bids and projects. I am new to data access development and LINQ so please forgive me if this is a daft question. :-O I am attempting to use LINQ to SQL to create a set of columns for populating a DataGridView using fields from multiple tables. My LINQ query is as follows: var bids = from bp in dc.BID_PROJECTs join company in dc.COMPANies on bp.Company_URN equals company.URN join pm in dc.EMPLOYEEs on bp.Management_Team_URN equals pm.URN select new { bp.BP_BPR, bp.BP_Title, bp.BP_Status, bp.BP_Type, company.Name, pm.Name }; The problem I am having is that both company and pm have 'Name' columns which causes Visual Studio to return the following when I attempt to compile: 'An anonymous type cannot have multiple properties with the same name' I have spent a long time looking for ways round this but to no avail, can I just apply an alias to one of the .Name properties? Thanks Jason
Jason Brown C# Developer
-
Hi, I have a smallish database that is used to record bids and projects. I am new to data access development and LINQ so please forgive me if this is a daft question. :-O I am attempting to use LINQ to SQL to create a set of columns for populating a DataGridView using fields from multiple tables. My LINQ query is as follows: var bids = from bp in dc.BID_PROJECTs join company in dc.COMPANies on bp.Company_URN equals company.URN join pm in dc.EMPLOYEEs on bp.Management_Team_URN equals pm.URN select new { bp.BP_BPR, bp.BP_Title, bp.BP_Status, bp.BP_Type, company.Name, pm.Name }; The problem I am having is that both company and pm have 'Name' columns which causes Visual Studio to return the following when I attempt to compile: 'An anonymous type cannot have multiple properties with the same name' I have spent a long time looking for ways round this but to no avail, can I just apply an alias to one of the .Name properties? Thanks Jason
Jason Brown C# Developer
DOH!!! :-O :-O :-O :-O var bids = from bp in dc.BID_PROJECTs join company in dc.COMPANies on bp.Company_URN equals company.URN join pm in dc.EMPLOYEEs on bp.Management_Team_URN equals pm.URN select new { bp.BP_BPR, bp.BP_Title, bp.BP_Status, bp.BP_Type, CompanyName = company.Name, PMName = pm.Name };
Jason Brown C# Developer