我有一個項目的簡單評級應用程序。主要有三個表:LINQ聯盟列如果驗證
Item
{
ItemID,
Contents
}
asp_User
{
UserID,
Name
}
Rating
{
RatingID,
ItemID,
UserID,
int Rating
}
我有LINQ代碼讀取項目:
var q = from item db.Item
select item;
那麼我想追加到包含評級的當前認證的每個項目行QA列用戶。如果用戶未登錄或沒有經過認證的用戶提供評級,結果將爲0.
如果有問題,我正在使用SqlMembershipProvider。
例
Q的最終結果應該是這個樣子:
[認證]
//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};
[未通過身份驗證]
//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};