我对linq很新。 我有一张二手车的桌子,可以在多个网站上发布。在此之上,每辆车都有多个图像。网站和图像通过链接表连接。
Cartable
可链接网站
网站表
可链接图片
图片标签
...
我知道如何执行表的连接,但基于链接表的选择不起作用
我现在拥有什么
Return From link In AixamReader.Link_Cars_Websites
Join car In AixamReader.Cars_SecondHandCars
On link.SecondHandCarID Equals car.SecondHandCarID
From imglink In AixamReader.Link_SecondHandCars_Images
Where imglink.SecondHandCarID = car.SecondHandCarID
Join webimg In AixamReader.WebSite_Images
On imglink.ImageID Equals webimg.ImageID
Where link.WebsiteID = pWebsiteID
And car.OnWebsite = True
Select car, webimg
如何为特定网站选择每辆车,然后为每辆车选择第一张图片。
帮助
答案 0 :(得分:0)
这应该有帮助
From webSiteCarLink In AixamReader.Link_Cars_Websites
Join car in AixamReader.SecondHandCars
On webSiteCarLink.CarID Equals car.CarID
Join carImageLink In AixamReader.Link_SecondHandCars_Images
On webSiteCarLink.CarID Equals carImageLink.CarID
Join image In AixamReader.WebSite_Images
On carImageLink.ImageID Equals image.ImageID
Where webSiteCarLink.WebsiteID = pWebsiteID
And car.OnWebsite = True
Group image By Key = car Into imageGroup
Select imageGroup.Key, imageGroup.FirstOrDefault();