Inserting a record into the database using EF 5.0 does not work. Debugging through my code I cannot find any exception. Looking through the code, it should insert a new record into the database, but when I look at the database, no new records are created. However, I made changes to my database and in debugging, when I check the "assestUser" (model), I can see all the values, including the deleted columns (the changes I made). Can someone please help me on what I am doing wrong? This is what I did:
Page:
public partial class _Default : Page { EntityContext context; public _Default() { context = new EntityContext(); } protected void btnSavePersonalDetails_Click(object sender, EventArgs e) { try { SkillsAssestUser assestUser = new SkillsAssestUser(); assestUser.DomainAcc = lblDomAcc.Text; assestUser.Name = txtName.Text; assestUser.Surname = txtSurname.Text; assestUser.Division = txtDivision.Text; assestUser.Manager = txtManager.Text; context.SkillsAssestUsers.Add(assestUser); context.SaveChanges();
Dbcontext:
public partial class EntityContext : DbContext { public EntityContext() : base("name=SOSConnectionString") { base.Configuration.LazyLoadingEnabled = true; base.Configuration.ProxyCreationEnabled = false; } #region AddTables public DbSet<AdditionalSkills> AdditionalSkillss { get; set; } public DbSet<CertifiedTraining> CertifiedTrainings { get; set; } public DbSet<OtherCertifiedTraining> OtherCertifiedTrainings { get; set; } public DbSet<OtherEdu> OtherEdus { get; set; } public DbSet<SchoolEdu> SchoolEdus { get; set; } public DbSet<SkillsAssestUser> SkillsAssestUsers { get; set; } public DbSet<ValueAddedSkills> ValueAddedSkillss { get; set; } #endregion } void Application_Start(object sender, EventArgs e) { // Code that runs on application startup AuthConfig.RegisterOpenAuth(); Database.SetInitializer<EntityContext>(null); }
What am I doing wrong? ... new to ef ....
source share