Entity Framework SaveChanges not saving to the database

c# ef-code-first entity-framework entity-framework-6

Question

My code isn't erroring out or anything when I put a try catch around it, but yet it still does not save to the database. Is there something I am missing?

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();

and my entity set looks sort of like

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
1
10/28/2016 5:45:38 PM

Popular Answer

Turns out i was unable to add to the tables since I had mapped the tabled in the .edmx to Create, Update, and Delete stored procedures. Once I removed the mapping I was able to add and update

1
10/28/2016 9:16:24 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow