我正在尝试计算我的数据库表中未读消息的数量,但事实证明这非常困难。我什至在网上阅读了教程,但无济于事。
我所做的应该很简单。
这是我正在尝试做的事情:
COUNT NUMBER OF ROWS IN NOTIFICATIONSTABLE
WHERE USERID = @0 AND MESSAGEWASREAD = FALSE
有人可以指出我正确的方向吗?任何帮助将不胜感激。
谢谢
@helper RetrievePhotoWithName(int userid)
{
var database = Database.Open("SC");
var name = database.QuerySingle("select FirstName, LastName, ProfilePicture from UserProfile where UserId = @0", userid);
var notifications = database.Query("SELECT COUNT(*) as 'counter' FROM Notifications WHERE UserID = @0 AND [Read] = @1", userid, false);
var DisplayName = "";
if(notifications["counter"] < 1)
{
DisplayName = name["FirstName"] + " " + name["LastName"];
}
else
{
DisplayName = name["FirstName"] + ", you have " + notifications["counter"] + " new messages.";
}
<a href="@Href("~/Home")" title="My Account"><img src="@Href("~/Shared/Assets/Images/" + name["ProfilePicture"] + ".png")" id="MiniProfilePicture" /> @DisplayName</a>
database.Close();
}