Entity Framework 更新带外键的实体为null

using (var ctx = new PortalContext())
{
    var city = ctx.Cities.Find(42);
    ctx.Entry(city)
        .Reference(c => c.Province)
        .Load();
    city.Province = null;

    ctx.SaveChanges();
}

posted @ 2016-03-30 17:44  lishidefengchen  阅读(475)  评论(0编辑  收藏  举报