【发布时间】:2014-03-07 00:26:40
【问题描述】:
使用 EF 5.0,这总是插入两条相同的记录。我只是想在我的数据库中创建一条新记录。我已经看过其他有关此的文章,但是很难将所有内容拼凑在一起,重新编码示例将极大地帮助我,而不是发布参考链接。提前谢谢你。
using (var context = new DBRegistrationEntities())
{
Registration coNew = new Registration();
coNew.user_id = userId;
coNew.parent_id = userId.ToString();
coNew.year = year;
coNew.created = new Nullable<DateTime>(DateTime.Now);
context.Registrations.Add(coNew);
context.SaveChanges();
}
【问题讨论】:
-
您是否检查过这段代码没有执行两次?
-
看起来不错,你能再贴一些代码吗?
-
failedprogramming 是正确的,我包含了额外的 javascript。如果您想回复“答案”,我会标记它。
标签: c# asp.net-mvc entity-framework entity-framework-5