I'm storing an IUser object in a Db4o database as follows (client is an IObjectClient):
public Guid AddUser(IUser user)
{
lock (userLock)
{
user.Id = Guid.NewGuid();
client.Store(user);
client.Commit();
}
return user.Id;
}
The implementation of IUser that is used here has the field that is discribed in IUser IEnumerable<Roles> Roles { get;}
implemented with a backing field IList<Roles> = new List<Roles>()
When I run the following UnitTest everything works fine:
[TestMethod]
public void UserStaysInRoleAfterServerRestart()
{
string filePath = IOHelper.MakeAbsolute(ConfigurationManager.AppSettings["userRepository.path.db4o"] + "1");
IUser expected = GenerateTestUser();
expected.AddRole(Roles.Anonymous);
IObjectServer userServer1 = Db4oFactory.OpenServer(filePath, 0);
IUserRepository repo = new UserRepository(userServer1);
repo.AddUser(expected);
userServer1.Close();
IObjectServer userServer2 = Db4oFactory.OpenServer(filePath, 0);
IUserRepository repo2 = new UserRepository(userServer2);
IUser actual = repo2.GetUser(expected.Id);
Assert.IsTrue(actual.IsInRole(Roles.Anonymous));
}
When I use the same methods (AddUser and GetUser) in my website, separated by a "restart debugging" however, the GetUser() returns the IUser correctly, but with the Roles.Count() == 0