public T[] CloneCollection <T>(CriteriaOperator sourceCriteria, SortProperty[] sortProperties, XpoDatabase target, bool synchronize = true, IEnumerable <XPClassInfo> excludedClasses = null, IEnumerable <string> synchronizeProperties = null) where T : IXPSimpleObject { if (target == null) { throw new ArgumentNullException("target"); } List <T> result = new List <T>(); using (Session sourceSession = this.GetSession()) { XPCollection sourceList = new XPCollection(sourceSession, typeof(T), sourceCriteria, sortProperties); if (sourceList.Count > 0) { using (UnitOfWork targetSession = target.GetUnitOfWork()) { Cloner c = new Cloner(sourceSession, targetSession, excludedClasses, synchronizeProperties); foreach (T sourceItem in sourceList) { result.Add(c.Clone <T>(sourceItem, synchronize)); } targetSession.CommitChanges(); } } } return(result.ToArray()); }
public static List <TDTOEntity> Select(XpoDatabase database, CriteriaOperator criteria = null, int pageSize = -1, int pageIndex = -1, params SortProperty[] sortProperties) { List <TDTOEntity> result = new List <TDTOEntity>(); using (UnitOfWork wrk = database.GetUnitOfWork()) { XPCollection <TXPOEntity> items = new XPCollection <TXPOEntity>(wrk, criteria, sortProperties); if (pageIndex > -1) { if (pageSize > -1) { items.SkipReturnedObjects = pageSize * pageIndex; } items.TopReturnedObjects = pageSize; } foreach (TXPOEntity item in items) { TDTOEntity dto = Activator.CreateInstance(typeof(TDTOEntity), item) as TDTOEntity; if (dto != null) { result.Add(dto); } } } return(result); }
public static void Insert(XpoDatabase database, IEnumerable <TDTOEntity> items, int savingFlags, Func <TDTOEntity, Exception[]> validateInsert, out TKey[] keyValues) { // Validate your input here !!!! if (validateInsert != null) { foreach (var item in items) { Exception[] validationResult = validateInsert(item); if (validationResult != null) { throw new Exception(String.Format("Insert Validation of {0} item failed:\n{1}", typeof(TDTOEntity).FullName, item.Key, String.Join("\n", (from e in validationResult select e.Message)))); } } } TKey[] ids = null; using (UnitOfWork wrk = database.GetUnitOfWork()) { wrk.ObjectsSaved += (sender, e) => { ids = (from n in e.Objects.OfType <TXPOEntity>() select n.Key).ToArray(); }; foreach (var item in items) { TXPOEntity dbItem = Activator.CreateInstance(typeof(TXPOEntity), wrk) as TXPOEntity; dbItem.Assign(item, savingFlags); } wrk.CommitChanges(); keyValues = ids; } }
public Task <T[]> CloneCollectionAsync <T>(CriteriaOperator sourceCriteria, SortProperty[] sortProperties, XpoDatabase target, bool synchronize = true, IEnumerable <XPClassInfo> excludedClasses = null, IEnumerable <string> synchronizeProperties = null) where T : IXPSimpleObject { return(Task.FromResult(CloneCollection <T>(sourceCriteria, sortProperties, target, synchronize, excludedClasses, synchronizeProperties))); }
public void Insert(XpoDatabase database, TDTOEntity items, int savingFlags, Func <TDTOEntity, Exception[]> validateInsert, out TKey keyValue) { TKey[] result; Insert(database, new TDTOEntity[] { items }, savingFlags, validateInsert, out result); if ((result != null) && (result.Length > 0)) { keyValue = result[0]; } else { keyValue = default(TKey); } }
public static TDTOEntity Select(XpoDatabase database, CriteriaOperator criteria, int loadingFlags = 0, bool raiseExceptionNotFound = false) { TDTOEntity result = null; using (UnitOfWork wrk = database.GetUnitOfWork()) { TXPOEntity item = wrk.FindObject <TXPOEntity>(criteria); if ((item == null) && raiseExceptionNotFound) { throw new Exception(String.Format("{0} Item not found on '{1}' not found", typeof(TXPOEntity).FullName, criteria.ToString())); } result = Activator.CreateInstance(typeof(TDTOEntity), item, loadingFlags) as TDTOEntity; } return(result); }
public static IQueryable <TDTOEntity> Select(XpoDatabase database, Expression <Func <TXPOEntity, bool> > filter = null, int pageSize = -1, int pageIndex = -1, params SortProperty[] sortProperties) { IQueryable <TDTOEntity> result; using (UnitOfWork wrk = database.GetUnitOfWork()) { var tmp = wrk.Query <TXPOEntity>().Where(filter); if ((pageIndex > -1) && (pageSize > 0)) { tmp = tmp.Skip(pageSize * pageIndex).Take(pageSize); } result = tmp.Select((xpo, i) => Activator.CreateInstance(typeof(TDTOEntity), xpo) as TDTOEntity); } return(result); }
public virtual Task <T> CloneAsync <T>(T source, XpoDatabase target, bool synchronize = true, IEnumerable <XPClassInfo> excludedClasses = null, IEnumerable <string> synchronizeProperties = null) where T : IXPSimpleObject { //if (source == null) // throw new ArgumentNullException("source"); //if (target == null) // throw new ArgumentNullException("targetSession"); //T result; //using (Session sourceSession = this.GetSession()) //using (UnitOfWork targetSession = target.GetUnitOfWork()) //{ // Cloner c = new Cloner(sourceSession, targetSession, excludedClasses, synchronizeProperties); // result = c.Clone<T>(source, synchronize); //} return(Task.FromResult(Clone(source, target, synchronize, excludedClasses, synchronizeProperties))); }
public static void Update(XpoDatabase database, IEnumerable <TDTOEntity> items, int savingFlags, Func <TDTOEntity, Exception[]> validateUpdate, bool insertOnNotFound = false, bool raiseExceptionOnNotFound = false) { // Validate your input here !!!! if (validateUpdate != null) { foreach (var item in items) { Exception[] validationResult = validateUpdate(item); if (validationResult != null) { throw new Exception(String.Format("Update Validation of {0} item({1}) failed:\n{2}", typeof(TDTOEntity).FullName, item.Key, String.Join("\n", (from e in validationResult select e.Message)))); } } } using (UnitOfWork wrk = database.GetUnitOfWork()) { foreach (var item in items) { TXPOEntity dbItem = wrk.GetObjectByKey <TXPOEntity>(item.Key); if (dbItem == null) { if (insertOnNotFound) { dbItem = Activator.CreateInstance(typeof(TXPOEntity), wrk) as TXPOEntity; } else if (raiseExceptionOnNotFound) { throw new Exception(String.Format("{0} Item with Id = '{1}' not found for updating", typeof(TXPOEntity).FullName, item.Key)); } } if (dbItem != null) { dbItem.Assign(item, savingFlags); } } wrk.CommitChanges(); } }
public static void Delete(XpoDatabase database, IEnumerable <TDTOEntity> items, Func <TDTOEntity, Exception[]> validateDelete) { // Validate your input here !!!! if (validateDelete != null) { foreach (var item in items) { Exception[] validationResult = validateDelete(item); if (validationResult != null) { throw new Exception(String.Format("Delete Validation of {0} item({1}) failed:\n{2}", typeof(TDTOEntity).FullName, item.Key, String.Join("\n", (from e in validationResult select e.Message)))); } } } using (UnitOfWork wrk = database.GetUnitOfWork()) { wrk.Delete(wrk.GetObjectsByKey(wrk.GetClassInfo <TXPOEntity>(), (from o in items select o.Key).ToArray(), false)); wrk.CommitChanges(); } }
public T Clone <T>(T source, XpoDatabase target, bool synchronize = true, IEnumerable <XPClassInfo> excludedClasses = null, IEnumerable <string> synchronizeProperties = null) where T : IXPSimpleObject { if (source == null) { throw new ArgumentNullException("source"); } if (target == null) { throw new ArgumentNullException("target"); } using (Session sourceSession = this.GetSession()) using (UnitOfWork targetSession = target.GetUnitOfWork()) { Cloner c = new Cloner(sourceSession, targetSession, excludedClasses, synchronizeProperties); T result = c.Clone <T>(source, synchronize); targetSession.CommitChanges(); return(result); } }
public XpoDtoDatasource(XpoDatabase database) : this() { _XpoDatabase = database; }
public XpoDtoDatasource(string connectionStringName) : this() { _XpoDatabase = new XpoDatabase(connectionStringName); }
public void Delete(XpoDatabase database, TDTOEntity item, Func <TDTOEntity, Exception[]> validateDelete) { Delete(database, new TDTOEntity[] { item }, validateDelete); }
public void Update(XpoDatabase database, TDTOEntity item, int savingFlags, Func <TDTOEntity, Exception[]> validateUpdate, bool insertOnNotFound = false, bool raiseExceptionOnNotFound = false) { Update(database, new TDTOEntity[] { item }, savingFlags, validateUpdate, insertOnNotFound, raiseExceptionOnNotFound); }
public static TDTOEntity Select(XpoDatabase database, TKey keyValue, int loadingFlags = 0, bool raiseExceptionNotFound = false) { return(Select(database, CriteriaOperator.Parse("[Id]==?", keyValue), loadingFlags, raiseExceptionNotFound)); }
public XPDataStore(XpoDatabase db, XPDataValidator <TKey, TModel, TXPOClass> validator = null) { xpo = db; val = validator; }
public XpoStore(XpoDatabase database) { _Database = database; }