Print Page | Close Window

Code example showing how to import entiies from one PM to another

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=196
Printed Date: 23-Oct-2025 at 5:44am


Topic: Code example showing how to import entiies from one PM to another
Posted By: Customer
Subject: Code example showing how to import entiies from one PM to another
Date Posted: 12-Jul-2007 at 3:21pm
Do you have a code example showing how to import entities from one PM to another?



Replies:
Posted By: IdeaBlade
Date Posted: 12-Jul-2007 at 3:23pm

I am uploading a sample solution  that shows how to import entities from one PM to another.  The sample solution uses two different SQL Server databases, and the application saves all changes to both databases

 
The sample solution uses a feature of DevForce called Data Source Extension.  When you use a Data Source Extension. you can use two PersistenceManagers each associated with the same schema, but having a different connection string.
 
Here are the two RdbKeys:
 .....
 
Open the first PersistenceManager normally.
 
mPM = PersistenceManager.DefaultManager;
mEmployees = mPM.GetEntities<Employee>();
 
Open the second PersistenceManager using the Data Extension signature:

mPmLegacy = new PersistenceManager(true, "Legacy");

Here is the 3 line snippet: 

private void SaveToLegacyDB() {
 mPmLegacy = new PersistenceManager(true, "Legacy");
 mPmLegacy.ImportEntities(mPM.GetEntities<Employee>(DataRowState.Modified | DataRowState.Added | DataRowState.Deleted), MergeStrategy.PreserveChanges);
 mPmLegacy.SaveChanges();
}



Print Page | Close Window