Take a look at this query:
var user = GetUser(userId);
var sessionInvites = ctx.SessionInvites
.Include("InvitingUser")
.Include("InvitedUser")
.Where(e => e.InvitedUser.UserId == user.UserId)
.ToList();
var invites = sessionInvites;
// Commenting out the two lines below, and it works as expected.
foreach (var invite in sessionInvites)
ctx.DeleteObject(invite);
ctx.SaveChanges();
return invites;
Now, everything here executes without any errors. The invites that exists for the user are being deleted and the invites are being returned with success.
However, when I then try to navigate to either InvitingUser
or InvitedUser
on any of the returned invites, I get NullReferenceException
. All other properties of the SessionIvites returned, works fine.
How come?
[EDIT] Now the weird thing is, if I comment out the lines with delete it works as expected. (Except that the entities will not get deleted :S)