实体框架SaveChanges未保存到数据库

时间:2016-10-28 16:20:29

标签: c# entity-framework ef-code-first entity-framework-6

我的代码没有错误输出或任何东西,当我尝试捕获它,但它仍然没有保存到数据库。有什么我想念的吗?

var newGroupMemberOf = new GroupMemberOf();
newGroupMemberOf.SamAcName = accountName;
newGroupMemberOf.MemberOf = parentSameAcName;
newGroupMemberOf.DateCreated = DateTime.Now;
newGroupMemberOf.DateUpdated = DateTime.Now;
newGroupMemberOf.IsActive = true;
newGroupMemberOf.Hidden = hidden;
newGroupMemberOf.ID = 12345678;

UserEntities.GroupMemberOf.Add(newGroupMemberOf);

UserEntities.SaveChanges();

我的实体集看起来有点像

public partial class UsersEntities : DbContext 
{ 
 public UsersEntities() 
    : base("name=UsersEntities") 
{ 
} 

protected override void OnModelCreating(DbModelBuilder modelBuilder) 
 {
  throw new UnintentionalCodeFirstException(); 
 }

 public virtual DbSet<GroupMemberOf> GroupMemberOf { get; set; }

1 个答案:

答案 0 :(得分:1)

原因是我无法添加到表中,因为我已将.edmx中的tabled映射到Create,Update和Delete存储过程。删除映射后,我就可以添加和更新