J'ai une simple application d'évaluation d'un article. Il y a trois tableaux principaux:LINQ Union Column Si Authentifié
Item
{
ItemID,
Contents
}
asp_User
{
UserID,
Name
}
Rating
{
RatingID,
ItemID,
UserID,
int Rating
}
Je code LINQ qui lit les articles:
var q = from item db.Item
select item;
Je voudrais ensuite ajouter à la colonne qa qui contient la note pour chaque ligne d'article du authentifié utilisateur. Si l'utilisateur n'est pas connecté ou s'il n'y a aucune évaluation fournie par l'utilisateur authentifié, le résultat sera 0.
J'utilise le SqlMembershipProvider si cela est important.
Exemple
Le résultat final de q devrait ressembler à ceci:
[assermentée]
//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};
[Non assermentée]
//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};