var forSentTable = new mailsent { Subject = Subject.Text, Mailbody = editor1.InnerText, SentTime = DateTime.Now, SentBy = mailFromEmail };
// var forSentTableBody = new MailSent { };
context.mailsents.Add(forSentTable);
//context.MailSents.Add(forSentTableBody);
context.SaveChanges();
//tried this one but not working with mysql(but it works with sql server)
var mailID = forSentTable.MailID;
答案 0 :(得分:1)
如果您使用数据库优先模型。您必须将Identity设置为model的StoreGeneratedPattern属性的值。 如果你使用代码第一模型。试试这个
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid ID { get; set; }