A developer has left our company, and has left us saddled with a bunch of C# code, using Entity Framework. I'm not a C# expert, and have never used Entity Framework. So - drinking from the end of a firehose.
I have a problem with one piece of code that isn't saving changes. At least not in a production or test environment from a web server. Running the code in debug will save the data each and every time. To the same test database that doesn't work when run from the web site (other data entry forms ARE saving to the database, just this one seems to be a problem).
I've researched, and a lot of suggestions seem to stem from Entity Framework not realizing the data is "actually" changed. So, I added a line of code to try to set the EntityState
to Added
in order to force it - still not joy.
public partial class xDBContext : DbContext
{
public xDBContext() : base("PromiseConnectionString")
{
}
}
...
public partial class xPromise_AllPrograms
{
[Key]
public int PrimID { get; set; }
public int FormId { get; set; }
[StringLength(100)]
public string Degree_Text { get; set; }
}
...
public ActionResult AddDegree(int formId, string degree)
{
using (xDBContext context = new xDBContext())
{
var program = new x_AllPrograms()
{
FormId = formId,
Degree_Text = degree
};
context.Promise_AllPrograms.Add(program);
context.Entry(program).State = System.Data.Entity.EntityState.Added;
context.SaveChanges();
}
return PartialView("_ViewPrograms", GetPrograms(formId));
}
Obviously, any Degree_Text
added should save into the resulting table, and will be re-displayed via GetPrograms
.
The data simply isn't saved - UNLESS I run it via debug on my local desktop.
Ideas?