New Posts New Posts RSS Feed: NullEntity in a list
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

NullEntity in a list

 Post Reply Post Reply
Author
chuckc View Drop Down
Groupie
Groupie


Joined: 27-Feb-2010
Posts: 54
Post Options Post Options   Quote chuckc Quote  Post ReplyReply Direct Link To This Post Topic: NullEntity in a list
    Posted: 06-Oct-2010 at 2:17pm


I am seeing some unexpected behavior regarding NullEntity.  Is this a bug?  Can NullEntities be added to lists as shown, or is that intrinsically not possible?

Thanks!


Contact contact = EntityManager.Contacts.FirstOrDefault();
User nullUser = EntityManager.GetNullEntity<User>();

try
{
   // At this point, contact.Users.Count == 0
   contact.Users.Add(nullUser);
}
catch (Exception e1)
{
   // Excepts with "Null or pending entities cannot be modified" - presumably because adding
   // the nullUser to the list contact.Users is internally trying to set an association key on nullUser.

   // However, the nullUser is actually added to the Users list.
   // contact.Users.Count is now 1

   bool wtf = false;
}

// Due to some odd behavior I was seeing elsewhere, I noticed that subsequent attempts do *not* except!
// Perhaps that is because the nullUser is already in the list?
try
{
   contact.Users.Add(nullUser);
}
catch (Exception e2)
{
   // Does not except on second attempt!
   bool wtf = true;
}

 

 

Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 07-Oct-2010 at 12:58pm
Chuck,
 
In the situation above the null entity should not be added to the Contact.Users list.
I am filing a bug for this issue.
 
As for the comment where subsequent attempts do not except, it's because you are trying to relate the same nullUser to the contact twice, so it doesn't even try to add the null entity the second time.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down