Inserting a record in the database using EF 5.0 isn't working. Debugging through my code I cannot find any exception. Going through the code it should insert a new record in the database, but when I look at the database there are no new records created. However, I did make changes to my database, and in debug when I check on the "assestUser" (the model) I can see all values, including the deleted columns (the changes I made). Could somebody please help me with what I am doing wrong? This is what I have done:
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();
//var assestUser = context.Set<SkillsAssestUser>();
//assestUser.Add(new SkillsAssestUser
//{
// DomainAcc = lblDomAcc.Text,
// Name = txtName.Text,
// Surname = txtSurname.Text,
// Division = txtDivision.Text,
// Manager = txtManager.Text
//});
//context.SaveChanges();
ClearPersonalDetails();
}
catch (Exception ex)
{
throw new Exception("Error inserting Details. " + ex.Message);
}
}
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....