【发布时间】:2013-10-19 14:58:58
【问题描述】:
我有三个表,其中两个是多对多关系。
图片:
这是中间mm表中的数据:
编辑: 到这里,我得到了正确的 4 行,但它们都是相同的结果(我知道我需要 4 行,但结果不同)
return this._mediaBugEntityDB.LotteryOffers
.Find(lotteryOfferId).LotteryDrawDates
.Join(this._mediaBugEntityDB.Lotteries, ldd => ldd.LotteryId, lot => lot.Id, (ldd, lot) =>
new Lottery
{
Name = lot.Name,
CreatedBy = lot.CreatedBy,
ModifiedOn = lot.ModifiedOn
}).AsQueryable();
我的问题是,我如何通过多对多表检索所有彩票,我只给出了 LotteryOfferId?
我想要实现的是通过 LotteryDrawDateId 从彩票表中获取数据。
首先我使用 LotteryOfferId 从中间表中获取 DrawDates,然后通过中间表获取 drawDateIds 以在 LotteryDrawDate 表中使用它们。从该表中,我需要通过 LotteryDrawDate 表中的 LotteryId 检索 Lottey 表。
我通过普通 SQL 获得了这一点(LotteryOffersLotteryDrawDates 是 DB 中的中间表,在模型中看不到):
选择 名称,Lotteries.CreatedBy,Lotteries.ModifiedOn,计数(Lotteries.Id) 来自 Lotteries 的 TotalDrawDates 加入 Lotteries.Id 上的 LotteryDrawDates = LotteryDrawDates.LotteryId 在 LotteryDrawDates.Id 上加入 LotteryOffersLotteryDrawDates = LotteryOffersLotteryDrawDates.LotteryDrawDate_Id 其中 LotteryOffersLotteryDrawDates.LotteryOffer_Id = 19 分组 名称、Lotteries.CreatedBy、Lotteries.ModifiedOn
但是 Linq 是不同的故事:P
我想用 lambda 表达式来做这件事。 谢谢
【问题讨论】: