New Posts New Posts RSS Feed: Code example showing how to import entiies from one PM to another
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

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

 Post Reply Post Reply
Author
Customer View Drop Down
Senior Member
Senior Member
Avatar
User Submitted Questions to Support

Joined: 30-May-2007
Location: United States
Posts: 260
Post Options Post Options   Quote Customer Quote  Post ReplyReply Direct Link To This Post Topic: Code example showing how to import entiies from one PM to another
    Posted: 12-Jul-2007 at 3:21pm
Do you have a code example showing how to import entities from one PM to another?
Back to Top
IdeaBlade View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 30-May-2007
Location: United States
Posts: 353
Post Options Post Options   Quote IdeaBlade Quote  Post ReplyReply Direct Link To This Post 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();
}
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down