This is a migrated thread and some comments may be shown as answers.

Synchronisation problem on existing objects of a changed class

4 Answers 83 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Nils
Top achievements
Rank 1
Nils asked on 31 Jan 2009, 12:54 AM
Hey guys,

we are devoloping our project completly using the ObjectContainer so that is could be used in disconnected scenarios. I altered on of our existing classes and added an IDictionary<string,string> to that class. I can work with the Dictionary inside the ObjectContainer normally (add/change/delete items in Dictionary). But as soon as I synchronise the container to the database all new items added to the dictionary inside objects already existing in the databare are lost.

There is no exception during the synchronisation.

I can change existing items inside the Dictionaries bu tall new items are lost during synchronisation.

We are using OpenAccess Version 2008.3 1205.

Any hints how I can use the Dictionary inside existing objects?

Thanks in advance,
Nils

4 Answers, 1 is accepted

Sort by
0
Nils
Top achievements
Rank 1
answered on 31 Jan 2009, 12:12 PM
One more post to make clear what exactly I am doing:

  1. Add a new object containing a dictionary (IDictionary<string,string>) to the ObjectContainer
  2. Add several KeyValuePair<string,string>-items to the dictionary.
  3. Change some of the items
  4. Remove some of the items
  5. Sync 1: Synchronize ObjectContainer to DB
  6. Change some of the items
  7. Add new items
  8. Sync 2

After Sync 2 all changes (6.) are copied to the database but all new items are lost (7.).

I have no idea why that happens.
Thanks, Nils
0
Jan Blessenohl
Telerik team
answered on 03 Feb 2009, 08:00 AM

using

 

System;

 

using

 

System.Collections.Generic;

 

using

 

Telerik.OpenAccess;

 

namespace

 

ContainerDictionaryProblem

 

{

 

class Program

 

{

 

static void Main(string[] args)

 

{

 

IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope();

 

scope.Transaction.Begin();

scope.Remove(scope.GetOqlQuery<

Test>().ExecuteEnumerable());

 

scope.Transaction.Commit();

 

ObjectContainer c = new ObjectContainer();

 

c.Transaction.Begin();

 

Test c1 = new Test();

 

c.Add(c1);

c1.dic.Add(

"1", "test");

 

c1.dic[

"1"] = "test2";

 

c1.dic.Add(

"2", "test");

 

c1.dic.Add(

"3", "test");

 

c.Transaction.Commit();

c.Apply(

ObjectContainer.CommitChanges(c.GetContent(), ObjectContainer.Verify.Changed, scope, false, true));

 

c.Transaction.Begin();

 

Test ct2 = c.Extent<Test>()[0];

 

ct2.dic[

"1"] = "test3";

 

ct2.dic.Remove(

"2");

 

ct2.dic.Add(

"4", "test");

 

ct2.dic.Add(

"5", "test");

 

ct2.dic.Remove(

"3");

 

c.Transaction.Commit();

 

ObjectContainer.CommitChanges(c.GetContent(), ObjectContainer.Verify.Changed, scope, false, false);

 

 

 

Test t = scope.GetOqlQuery<Test>().ExecuteList()[0];

 

 

Console.WriteLine(t);

 

}

}

[

Persistent]

 

 

class Test

 

{

 

public IDictionary<string, string> dic = new Dictionary<string, string>();

 

 

public override string ToString()

 

{

 

string ret = "Test:\r\n";

 

 

foreach(var v in dic)

 

{

ret +=

"Key: " + v.Key + " Value: " + v.Value +"\r\n";

 

}

 

return ret;

 

}

}

}



Sincerely yours,
Jan Blessenohl
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Nils
Top achievements
Rank 1
answered on 05 Feb 2009, 01:30 AM
Hi Jan,
thanks for your suggestion. It was not easy to understand ;) But thats just because of the broken formatting. I played around with your solution and in the end I figured out the problem in our solution.

It was no synchronisation problem but it shows after synchronisation. The problem was that I added a KeyValuePair<string, string> to the Dictionary. The KeyValuePair was not explicit added to the container but only to the dictionary.
startTransaction(); 
classWithPropertyList.CustomPropertiesList.Add(pair); 
commitTransaction(); 

Using the container everything works fine but during synchronisation these KeyValuePairs weren't transfered to the database. Using
classWithPropertyList.CustomPropertiesList.Add(pair.Key, pair.Value); 
instead fixed the problem.

Thanks for your help. Without it I would have spent even more hours on researching this strange behavior.

Do you know why that happens?

Thanks,
Nils


0
Accepted
Jan Blessenohl
Telerik team
answered on 06 Feb 2009, 02:57 PM
Hello Nils,
That is indeed a bug. We do not mark the dictionary dirty if you change it with this add method. It will be fixed in the next patch.

You will find your Telerik points in your account.

Sincerely yours,
Jan Blessenohl
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
General Discussions
Asked by
Nils
Top achievements
Rank 1
Answers by
Nils
Top achievements
Rank 1
Jan Blessenohl
Telerik team
Share this question
or