C# - Entity Framework : explicitly loading a reference object
1
2
3
4
5
6
7
8
9
10
11
using (var context = new BreakAwayContext())
{
var davesDump = (from l in context.Lodgings
where l.Name == "Dave's Dump"
select l).Single();
context.Entry(davesDump)
.Reference(l => l.PrimaryContact)
.Load();
davesDump.PrimaryContact = null;
context.SaveChanges();
}