我无法将我的 Entity Framework 4.3 代码第一个数据库中的外键更新为 null。
我的视图模型:
public class AccountViewModel
{
public int Id { get; set; }
public int? CorporationId { get; set; }
public CorporationModel Corporation { get; set; }
}
var corporation = db.Corporation.Where(x => x.Id == model.CorporationId).FirstOrDefault(); // shows as null
account.Corporation = corporation; // sets the value to null
db.Entry(account).State = EntityState.Modified;
db.SaveChanges(); // does not save the null value in the FK field!!!
任何帮助将不胜感激。