Only Bolivian Here
Only Bolivian Here

Reputation: 36743

Need help with a simple Linq query running with Entity Framework 4

Here's the code:

var userA = auction.UserAuctionLances.OrderByDescending(d => d.DateTimeOfLance)
                                     .Select(u => u.User).FirstOrDefault();

Here's a view of the data in my database, specifically the UserAuctionLance table.

enter image description here

And here's a view of the tables relationships. Remember I'm using Entity Framework:

enter image description here

Basically, I want to get the .Login property of the last User who bid in the auction. However, my Linq query is fetching the very first user in the User table.

What am I doing wrong?

Upvotes: 0

Views: 71

Answers (1)

Yahia
Yahia

Reputation: 70369

use

var userA = auction.UserAuctionLances.OrderByDescending(d => d.DateTimeOfLance).FirstOrDefault().User;

Upvotes: 3

Related Questions