public class Message { [Key, Column(Order = 1)] public int UserId {get;set;} [Key, Column(Order = 2)] public int MessageId {get;set;} public string Body {get;set;} } There is an essence Message. Is it possible to somehow automatically generate a MessageId when added within a single UserId?
And if not, is this option acceptable?
int userId = 1; var message = new Message(); int lastMessageId = db.Messages.Where(m=>m.UserId==userId).OrderByDescending(m=>m.MessageId).First().MessageId; message.MessageId = lastMessageId + 1; db.Messages.Add(message);
idto sort and take them first, but simply to find the maximum. - teran