非常简单的问题,但我今天早上似乎过得很不顺利。
到目前为止,我已经构建了以下查询,我想选择返回结果中的第一个对象,但不是 ID 本身,而是具有该 ID 的基础用户。
这有意义吗?
//Edited the code for clarity!
After this OrderBy is run,
I have collection I want,
but I need to select the USER
no the UserAuctionLance.
var user = db.UserAuctionLances.Where(a => a.AuctionId == id).OrderByDescending(s => s.DateTimeOfLance).Select??
“将所有用户的出价按日期降序排列,并给出最后一个对拍卖编号 Foo 出价的用户。”
也许这让问题更清楚了。我需要返回一个用户对象。
感谢您的宝贵时间。
请您参考如下方法:
我相信你想要:
var user = db.UserAuctionLances.Select(a=>a).Where(a => a.AuctionId == id).OrderByDescending(s => s.DateTimeOfLance).FirstOrDefault();
这应该返回第一个结果,如果不存在则返回 null。
正如您在下面解释的那样,您希望 userAuctionLances 中的用户对象更像是:
var user = db.UserAuctionLances.Where(a => a.AuctionId == id).OrderByDescending(s => s.DateTimeOfLance).Select(a=>a.UserObject).FirstOrDefault();
