Print Page | Close Window

Default PersistenceOrder wrong

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=832
Printed Date: 25-Oct-2025 at 4:55pm


Topic: Default PersistenceOrder wrong
Posted By: lokheed
Subject: Default PersistenceOrder wrong
Date Posted: 07-Jun-2008 at 6:46am
In our installation, when persisting new objects to the db in which there are foreign key constraints, it seems that regularly the PersistenceManager.DefaultSaveOptions.PersistenceOrder is not taking those foreign key constraints into consideration when creating the list.  This means that I have had to create a method that casts the PersistenceOrder into a Type array, manually sort the items in that array to take those constraints into account, and then call PersistenceManager.DefaultSaveOptions.SetPersistenceOrder() with the corrected Type array.

My question is, should I really have to do that?  Is there some step or setting I am missing that is causing the persistence manager to not automatically notice those constraints?



Replies:
Posted By: davidklitzke
Date Posted: 08-Jun-2008 at 8:23am

DevForce  uses a Reverse Topological sort to calculate a default Persistence Order.  Occasionally, we hear complaints that the order is not always correct.  After an in-depth analysis of these cases, we have found a couple of contributing causes:  

(1)  There are too many relationships and/or some contradictory relationships and  the problem cannot really be solved.  Simplifying the relationships and reducing the number of relationships can sometimes help.

(2) There are too few and/or missing relationships.  A good example occurs with grandparent-parent-child relationships.  Sometimes the relationship between grandparent and child is not declared and the missing relationship shows up as an apparent persistence order problem. 

In most cases, we find that subtracting relationships or adding missing relationships can solve the problem.  .

I am not saying that there is a better solution to your problem, but we might be able to help you if you could give us a specific example.

 



Posted By: lokheed
Date Posted: 08-Jun-2008 at 8:55am
Could it be because we are using two different databases (both are on the same server)? 

The majority of the application uses something like PrimaryDB but the business objects I am having trouble with are all in CustomModuleDB.  So CustomModuleDB.dbo.Foo.BarID is a fk constraint to PrimaryDB.dbo.Bar.BarID, and then then there are several tables in CustomModuleDB that have foreign key constraints to CustomModuleDB.dbo.Foo.FooID.  What I am seeing is that all of the business objects generated from PrimaryDB are sorted properly, it's the business objects from CustomModuleDB that tend to get out of order. I don't have the option to migrate the tables from CustomModuleDB into PrimaryModuleDB.

What I will try is to run a topological sort on just the business objects from CustomModuleDB within the list, leaving all of the business objects from PrimaryDB in their relative order.


Posted By: davidklitzke
Date Posted: 08-Jun-2008 at 9:43am

Do you have the relationships between tables from the two differenves databases defined in the Object Mapper.  That could explain your problem.  If you only have the relationships defined for tables in the same database, the DevForce Framework can't possibly get the Persistence Order correct.  Look at the Advanced Tutorial on "Working with Multiple Databases" for an example.

 




Print Page | Close Window