I'm trying to update an object that I have previously saved with EntityFramework 4.1 (CodeFirst)
The class Job has the following properties ...
public class Job
{
[key]
public int Id { get; set; }
public string Title { get; set; }
public Project Project { get; set; }
public JobType JobType { get; set; }
public string Description { get; set; }
}
The initial create works fine, but the update only commits changes to the strings..
If I change the child objects eg the JobType
Property from JobTypeA
to JobTypeB
- the change is not committed ...
I'm not looking to commit a change to JobType - only to Job.
using (var context = new JobContext())
{
context.Jobs.Attach(job);
context.Entry(job).State = EntityState.Modified;
context.SaveChanges();
}
Having a look at SQL Profiler - the Ids are not even being sent for the Update - however they are for the initial insert!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…