I’m trying to convert this SQL query to LINQ:
SELECT Items.p_Name Product, DiamondCategory.dc_Name Category, Diamond.d_Weight Weight
FROM DiamondCategory
INNER JOIN Diamond ON DiamondCategory.dc_Id = Diamond.dc_Id
INNER JOIN Items ON Diamond.p_Id = Items.p_Id where Items.p_Id = 1
Union gives no results:
var qry = (from d in myDatabaseDataSet.Diamond select d.d_Weight).Union
(from c in myDatabaseDataSet.Items select c.p_Name).Union
(from e in myDatabaseDataSet.DiamondCategory select e.dc_Name);
Uniondoes not do what you want, you need aJoin. This is the general answer:EDIT: From your tags, it seems like you are using LINQ to SQL. If so, then something like this would suffice, assuming you have foreign key constraints between the tables you’ve mentioned: