I have a simple rating application of an Item. There are three main tables:
Item
{
ItemID,
Contents
}
asp_User
{
UserID,
Name
}
Rating
{
RatingID,
ItemID,
UserID,
int Rating
}
I have linq code that reads the items:
var q = from item db.Item
select item;
I would then like to append to q a column that contains the rating for each item row of the currently authenticated user. If the user is not logged in or there is no rating provided by the authenticated user, the result will be 0.
I'm using the SqlMembershipProvider if that matters.
Example
The final result of q should look something like this:
[Authenticated]
//The currently authenticated user has commented on Item.ID = 1 and has given it a 9.
q = {ID = 1, Contents = "Whatever", Rating = 9},
//The currently Authenticated user has not commented on Item.ID = 2.
{ID = 2, Contents = "Something", Rating = 0};
[Not Authenticated]
//There is not an authenticated user
q = {ID = 1, Contents = "Whatever", Rating = 0},
//There is not an authenticated user
{ID = 2, Contents = "Something", Rating = 0};