我有一个简单的问题
我正在开发聊天系统服务,但我遇到了一些有趣的事情。
我目前是这样操作的:
第一个表:
[Messages] :
SenderID(user),
RecipientID(user),
Content(string)
当然,每次用户向其他用户发送消息时,我都会将其添加到表中。但我想到如果一个表有一百万行,它会变得一团糟
所以我想到了另一种方式:
第一个表:
[Conversation]
ConversationID,
USER1(user),
USER2(user)
第二个表:
[Messages] in which I have
ConversationID,
Content(string)
所以基本上,我问,我应该使用哪种配置?
最佳答案
下面的方法应该能够帮助你解决问题。这是聊天和消息传递的良好基础,通过聊天,您可以从客户端轮询最近的消息并使用直观的 UI。
留言
Message {
MessageId,
FromId, -- Foreign key User.UserId
ToId, -- Foreign key User.UserId
Subject,
Content,
Attachment, -- can be null or default to a 0
DateReceived, -- can be null or default to 1901 or sumin'
DateRead
...
}
用户
User {
UserId
UserName
...
}
查询
Inbox = Message where ToId = Me.UserId
Sent = Message where FromId = Me.UserId
Conversation = Group by Subject
Attachment = (Simple = Path to attachment file. || Better = DocumentId)
附件
Document {
int DocumentId,
int DocTypeId,
virtual DocumentType DocumentType,
string FileName,
int UserId,
string mimeType,
float fileSize,
string storagePath,
int OrganizationId,
string fileHash,
string ipAddress,
DateTime DateCreated = DateTime.Now;
}
然后您遇到了群聊问题。您是向群组中的每个收件人发送消息还是创建每个收件人都有权访问的单个消息?
但我们保持简单。
关于asp.net-mvc - 如何使用 Entity Framework 在 C# 中建模消息/聊天系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30519513/