-
-
Save LSTANCZYK/14a2020e87b63fb51894 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void CopyDataToNewDatabase() | |
{ | |
//get all data from current database | |
//(database connection strored in other place and initialize by _unitOfWork) | |
XPCollection<Item> items = new XPCollection<Item>(_unitOfWork); | |
items.Load(); | |
//prepare new connection string to other database | |
string fileLocation = System.Web.Hosting.HostingEnvironment.MapPath(@"~\App_Data\multi_language.db"); | |
string conn = DevExpress.Xpo.DB.SQLiteConnectionProvider.GetConnectionString(fileLocation); | |
DevExpress.Xpo.Metadata.XPDictionary dict = new DevExpress.Xpo.Metadata.ReflectionDictionary(); | |
dict.GetDataStoreSchema(typeof(Item).Assembly); | |
DevExpress.Xpo.XpoDefault.Session = null; | |
DevExpress.Xpo.DB.IDataStore store = DevExpress.Xpo.XpoDefault.GetConnectionProvider(conn, DevExpress.Xpo.DB.AutoCreateOption.DatabaseAndSchema); | |
//create new session with new connection | |
using (UnitOfWork uow = new UnitOfWork(new DevExpress.Xpo.ThreadSafeDataLayer(dict, store), null)) | |
{ | |
//loap each data collection | |
foreach (Item item in items) | |
{ | |
//save to new tables in new database | |
Item newItem = new Item(uow); | |
newItem.ItemID = item.ItemID; | |
newItem.SerialNumber = item.SerialNumber; | |
newItem.Description = item.Description; | |
newItem.Manufacturer = item.Manufacturer; | |
newItem.Supplier = item.Supplier; | |
newItem.ManufacturerCN = item.ManufacturerCN; | |
newItem.Save(); | |
} | |
uow.CommitChanges(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment