0

我正在尝试将几个表与以下代码一起加入

  var result = (from n in db.tbl_NAWs
                join s in db.Status on n.Status equals s.StatusID
                join a in db.tbl_Afdelings on n.Afdeling equals a.ID_Afdeling
                join l in db.Locaties on n.Locatie equals l.LocatieID
                select new NAW_Dto()
                {
                    ClassNR = n.ClassNr,
                    Status = s.Beschrijving,
                    Client = n.Aanspreekvorm,
                    Locatie = l.Naam,
                    Afdeling = a.Afdeling,
                    KamerNr = n.Kamernummer
                }).ToList();

但它一直空着,有什么想法吗?

4

3 回答 3

0

运行 Sql Profiler,检查正在执行的实际 SQL 查询是什么,并查看您的数据。

无法在没有看到数据的情况下说出为什么结果集为空。您的外键是否按照您认为的方式设置?

尝试在删除一些连接的情况下执行此查询 - 您将能够以这种方式找到有问题的连接。

于 2012-06-08T12:13:29.767 回答
0

尝试这样的事情......

  var result = (from n in db.tbl_NAWs
                join s in db.Status on n.Status equals s.StatusID
                join a in db.tbl_Afdelings on n.Afdeling equals a.ID_Afdeling
                join l in db.Locaties on n.Locatie equals l.LocatieID
                select new 
                {
                    ClassNR = n.ClassNr,
                    Status = s.Beschrijving,
                    Client = n.Aanspreekvorm,
                    Locatie = l.Naam,
                    Afdeling = a.Afdeling,
                    KamerNr = n.Kamernummer
                }).ToList();
于 2012-06-08T12:21:44.300 回答
0

将其分解为 TSQL 并在 SSMS 中运行 一次删除一个注释,看看哪个不匹配

select n.ClassNr
-- , s.Beschrijving
-- , a.Afdeling
-- , l.Naam
from tbl_NAWs as n
-- join Status as s on n.Status equals s.StatusID
-- join tbl_Afdelings as a on n.Afdeling equals a.ID_Afdeling
-- join Locaties as l on n.Locatie equals l.LocatieID
于 2012-06-08T12:54:19.357 回答