linq 多表查询问题 请教
我的需求是danzhengp表里面的公司id去公司表里面查公司名称
var query = from o in sdb.danzhengp
select new
{
id = o.ID,
sno = o.SNO,
chuancompany =from t in sdb.company where t.ID == o.CHUANID select t.NAME,
chuanming = o.CHUANMING,
jgdate = o.JGDATE,
qygdate = o.QYGDATE,
ifdock = o.ifdcok
};
生成的sql 多了ORDER BY [t0].[ID], [t1].[ID] 老是报错
在排序依据列表中多次指定了某一列。排序依据列表中的列必须是唯一的。
很奇怪 我都没有写order by怎么自动生成的
SELECT [t0].[ID] AS [id], [t0].[SNO] AS [sno], [t1].[NAME], (
SELECT COUNT(*)
FROM [dbo].[company] AS [t2]
WHERE ([t2].[ID]) = [t0].[CHUANID]
) AS [value], [t0].[CHUANMING] AS [chuanming], [t0].[JGDATE] AS [jgdate], [t0].[QYGDATE] AS [qygdate], [t0].[ifdcok] AS [ifdock]
FROM [dbo].[danzhengp] AS [t0]
LEFT OUTER JOIN [dbo].[company] AS [t1] ON ([t1].[ID]) = [t0].[CHUANID]
ORDER BY [t0].[ID], [t1].[ID]
------解决方案--------------------我模仿了一下你的实现不存在你所谓的出错啊
var result = from user in school.Courses select new { name=user.CourseID,id=user.DepartmentID, daxue=school.Departments.Where(r=>r.DepartmentID==user.DepartmentID).Select(r=>r.Name)};
我用的是ef4.0