views:

50

answers:

3

Hi

I have the following situation:

role.Permissions.Add(permission);
objectContext.SaveChanges();

When I now take a look in the relations table Roles_Permissions the newly added permission to the role is not present. It only saves the new relation when I dispose the object context. Am I doing something wrong or does a call to SaveChanges doesn't save changes on relationship sets?

A: 

It sounds like you are using a transaction.

The changes made are not visible outside the transaction scope untill the transaction is committed.

And the transaction scope is not being committed until the object context is disposed.

Shiraz Bhaiji
I'm not using a transaction. Is it possible that EF creates a transaction automaticly? If so, can I get the transaction somehow to trigger the commit?
Mato
Check the constructor or the properties of your object context. But you should close your object context as soon as possible, so it is probably not a problem.
Shiraz Bhaiji
A: 

Just check whether they are in the same objectContext.

franklins
A: 

You can ensure that your permission entity is known to your object context by executing the following line of code:

objectContext.AddObject("Permissions", permission);

Ryan Gamal