0

用户:

userid    name     email
  1       venkat   v@g.com
  2       venu     ve@g.com
  3       raghu    r@g.com

伙伴:

    id   userid   partnerid  status
    1     1        2           1
    2     1        3           1

地点:

    id   userid    lat    lon
    1     1        12.00  13.00
    2     2        14.00  12.00
    3     3        14.00  14.23

询问:

var result = from partner in Partners
                join user in Users on partner.UserId equals user.PartnerId
                join location in Locations on patner.UserId equals location.PartnerId
                where partner.UserId == 1
                select new { PartnerId = partner.PartnerId, PartnerName = user.Name, Lat = location.Lat, Lon = location.Lon };

通过userid=1作为参数传递,我得到了这个结果:

partnerid  patnername      lat            lon
  2         venkat         14.00         12.00
  3         venkat         14.00         14.23

通过观察上述结果,这里的合作伙伴名称是错误的partnerid = 2-patname只是 venu显示“venkat”

因为partnerid = 3,partnernameraghu只是显示venkat

如何显示正确的合作伙伴名称?

4

1 回答 1

1

我相信这里的 JOIN 是错误的:

var result = from partner in Partners
             join user in Users on user.UserId equals partner.PartnerId

您正在将他的用户加入userId到使用他的合作伙伴中PartnerID

PartnerID在这两种情况下都不需要将用户加入到合作伙伴中吗?像这样的东西:

var result = from partner in Partners
             join user in Users on user.PartnerId equals partner.PartnerId
于 2012-05-02T05:26:56.013 回答