【发布时间】:2011-12-12 15:22:35
【问题描述】:
我正在尝试更新我之前使用 EntityFramework 4.1 (CodeFirst) 保存的对象
Job 类具有以下属性...
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; }
}
初始创建工作正常,但更新只提交对字符串的更改..
如果我将子对象(例如 JobType 属性从 JobTypeA 更改为 JobTypeB - 未提交更改...
我不打算对 JobType 进行更改 - 只是对 Job。
using (var context = new JobContext())
{
context.Jobs.Attach(job);
context.Entry(job).State = EntityState.Modified;
context.SaveChanges();
}
查看 SQL Profiler - 甚至没有为更新发送 Id - 但是它们用于初始插入!
【问题讨论】:
标签: c# entity-framework ef-code-first code-first