I am currently building a chat system in signalr and want to be able to store user messages into the database.
If each user can join different groups and private message each other, and all this data is saved into the db so their history can be reloaded upon returning I need a solid framework. I will give my plan, and would like to hear your thoughts/suggestions.
Each user is mapped as many users to many other users. u <-> mu.
Each user could talk to just a few or many users.
But each user can only talk to one instance of another user and they then share the same history
Therefore I could map a dictionary per user with string pairs and say IF this user and this user are not mapped in the same pair then create new history, in which case create a new id which will link to the history.
Now then, for the reason I linked LINQ and EF above. I've been doing some reading, and I am thinking there must be a better way than checking one column, finding a key or generating a new one, and accessing the history.
My question is, how would be best to map it in EF? I want to switch over to this rather than SQL plugging as it means I can move back away from the db and create layering but I lack an understanding of how to accomplish this.
Many thanks
This is what I have so far:
public class PrivateMessage {
public int MessageId { get; set; }
public string Message { get; set; }
public DateTime TimeStamp { get; set; }
public virtual Dictionary<user,> Pair { get; set; }
}
public class User {
public int UserId { get; set; }
public string UserName { get; set; }
}
public class PrivateMessageContext : DbContext
{
public DbSet<privatemessage> PrivateMessages { get; set; }
}
public void Send(userTo, userFrom, message) {
using (var db = new PrivateMessageContext())
{
var PrivateMessage = new PrivateMessage { Name = name };
db.PrivateMessages.Add(PrivateMessage);
db.SaveChanges();
}
}