IList <EntityDTO> IDeleteInfo.GetDependEntities(IDeleteCore core, ClearDependenceInfo depend, EntityDTO masterEntity) { var list = core.UoW.Session.CreateCriteria(ObjectClass) .Add(Restrictions.Eq(depend.PropertyName + ".Id", (int)masterEntity.Id)).List(); return(MakeResultList(list)); }
internal override void Execute(IDeleteCore core, CancellationToken cancellation) { if (cancellation.IsCancellationRequested) { return; } ChildBeforeOperations.ForEach(o => o.Execute(core, cancellation)); if (cancellation.IsCancellationRequested) { return; } core.AddExcuteOperation(String.Format("Удаляем из таблицы {0}", TableName)); core.ExecuteSql( String.Format("DELETE FROM {0} {1}", TableName, WhereStatment), ItemId); if (cancellation.IsCancellationRequested) { return; } ChildAfterOperations.ForEach(o => o.Execute(core, cancellation)); }
IList <EntityDTO> IDeleteInfo.GetDependEntities(IDeleteCore core, DeleteDependenceInfo depend, EntityDTO masterEntity) { if (depend.PropertyName != null) { var list = core.UoW.Session.CreateCriteria(ObjectClass) .Add(Restrictions.Eq(depend.PropertyName + ".Id", (int)masterEntity.Id)).List(); return(MakeResultList(list)); } else if (depend.CollectionName != null) { CheckAndLoadEntity(core, masterEntity); return(MakeResultList( masterEntity.Entity.GetPropertyValue(depend.CollectionName) as IList)); } else if (depend.ParentPropertyName != null) { CheckAndLoadEntity(core, masterEntity); var value = (TEntity)masterEntity.Entity.GetPropertyValue(depend.ParentPropertyName); return(MakeResultList(value == null ? new List <TEntity>() : new List <TEntity> { value })); } throw new NotImplementedException(); }
internal override void Execute(IDeleteCore core) { var sql = $"UPDATE {TableName} SET {CleanField} = NULL " + WhereStatment; core.AddExcuteOperation(String.Format("Очищаем ссылки в таблице {0}", TableName)); core.ExecuteSql(sql, ItemId); }
IList <EntityDTO> IDeleteInfo.GetDependEntities(IDeleteCore core, DeleteDependenceInfo depend, EntityDTO masterEntity) { if (depend.PropertyName != null) { var list = core.UoW.Session.CreateCriteria(ObjectClass) .Add(Restrictions.Eq(depend.PropertyName + ".Id", (int)masterEntity.Id)).List(); return(MakeResultList(list)); } else if (depend.CollectionName != null) { CheckAndLoadEntity(core, masterEntity); return(MakeResultList( masterEntity.Entity.GetPropertyValue(depend.CollectionName) as IList)); } else if (depend.ParentPropertyName != null) { CheckAndLoadEntity(core, masterEntity); var value = (TEntity)masterEntity.Entity.GetPropertyValue(depend.ParentPropertyName); try { NHibernateUtil.Initialize(value); } catch (ObjectNotFoundException ex) { logger.Error($"{masterEntity.ClassType}#{masterEntity.Id}.{depend.ParentPropertyName} ссылается на {ex.EntityName}, но его нет в базе данных."); value = null; masterEntity.Entity.SetPropertyValue(depend.ParentPropertyName, null); } return(MakeResultList(value == null ? new List <TEntity>() : new List <TEntity> { value })); } throw new NotImplementedException(); }
internal override void Execute(IDeleteCore core, CancellationToken cancellation) { if (cancellation.IsCancellationRequested) { return; } ChildBeforeOperations.ForEach(o => o.Execute(core, cancellation)); if (cancellation.IsCancellationRequested) { return; } core.AddExcuteOperation(String.Format("Удаляем {0}", DomainHelper.GetSubjectNames(DeletingItems[0].Entity)?.NominativePlural)); foreach (var item in DeletingItems) { if (cancellation.IsCancellationRequested) { return; } logger.Debug($"Удаляем [{item.Id}] {item.Title}..."); core.UoW.TryDelete(item.Entity); } if (cancellation.IsCancellationRequested) { return; } ChildAfterOperations.ForEach(o => o.Execute(core, cancellation)); }
internal override void Execute(IDeleteCore core) { core.AddExcuteOperation(String.Format("Очищаем коллекции в {0}", DomainHelper.GetSubjectNames(RemoveInClassType).NominativePlural)); var collectionProp = RemoveInClassType.GetProperty(CollectionName); var removeMethod = String.IsNullOrEmpty(RemoveMethodName) ? null : RemoveInClassType.GetMethod(RemoveMethodName); foreach (var item in RemoveInItems) { logger.Debug("Удаляем {2} из коллекции {0} в {1}...", CollectionName, item.Title, RemovingEntity.Title); if (removeMethod != null) { if (item.Entity is IBusinessObject) { (item.Entity as IBusinessObject).UoW = core.UoW; } removeMethod.Invoke(item.Entity, new object[] { RemovingEntity.Entity }); } else { var collection = (IList)collectionProp.GetValue(item.Entity, null); collection.Remove(RemovingEntity.Entity); } core.UoW.TrySave(item.Entity); } }
IList <EntityDTO> IDeleteInfo.GetDependEntities(IDeleteCore core, RemoveFromDependenceInfo depend, EntityDTO masterEntity) { var list = core.UoW.Session.CreateCriteria(ObjectClass) .CreateAlias(depend.CollectionName, "childs") .Add(Restrictions.Eq(String.Format("childs.Id", depend.CollectionName), (int)masterEntity.Id)).List(); return(MakeResultList(list)); }
internal override void Execute(IDeleteCore core) { ChildBeforeOperations.ForEach(o => o.Execute(core)); core.AddExcuteOperation(String.Format("Удаляем из таблицы {0}", TableName)); core.ExecuteSql( String.Format("DELETE FROM {0} {1}", TableName, WhereStatment), ItemId); ChildAfterOperations.ForEach(o => o.Execute(core)); }
EntityDTO IDeleteInfo.GetSelfEntity(IDeleteCore core, uint id) { var item = core.UoW.GetById <TEntity> ((int)id); return(new EntityDTO { Id = (uint)item.Id, ClassType = ObjectClass, Title = DomainHelper.GetObjectTilte(item), Entity = item }); }
internal override void Execute(IDeleteCore core, CancellationToken cancellation) { if (cancellation.IsCancellationRequested) { return; } var sql = $"UPDATE {TableName} SET {CleanField} = NULL " + WhereStatment; core.AddExcuteOperation(String.Format("Очищаем ссылки в таблице {0}", TableName)); core.ExecuteSql(sql, ItemId); }
internal override void Execute(IDeleteCore core) { core.AddExcuteOperation(String.Format("Очищаем ссылки в {0}", DomainHelper.GetSubjectNames(EntityType).NominativePlural)); var propertyCache = EntityType.GetProperty(PropertyName); foreach (var item in ClearingItems) { logger.Debug("Очищаем свойство {0} в {1}...", PropertyName, item.Title); propertyCache.SetValue(item.Entity, null, null); core.UoW.TrySave(item.Entity); } }
internal override void Execute(IDeleteCore core) { ChildBeforeOperations.ForEach(o => o.Execute(core)); core.AddExcuteOperation(String.Format("Удаляем {0}", DomainHelper.GetSubjectNames(DeletingItems[0].Entity).NominativePlural)); foreach (var item in DeletingItems) { logger.Debug("Удаляем {0}...", item.Title); core.UoW.TryDelete(item.Entity); } ChildAfterOperations.ForEach(o => o.Execute(core)); }
private bool CheckAndLoadEntity(IDeleteCore core, EntityDTO entity) { if (entity.Entity != null) { return(true); } if (entity.ClassType == null) { throw new InvalidOperationException("EntityDTO без указания класса не может использоваться в связке с NHibernate"); } entity.Entity = core.UoW.GetById(entity.ClassType, (int)entity.Id); return(entity.Entity != null); }
internal abstract void Execute(IDeleteCore core, CancellationToken cancellation);
EntityDTO IDeleteInfo.GetSelfEntity(IDeleteCore core, uint id) { return(GetEntitiesList(String.Format("WHERE {0}.id = @id", TableName), id)[0]); }
IList <EntityDTO> IDeleteInfo.GetDependEntities(IDeleteCore core, DeleteDependenceInfo depend, EntityDTO masterEntity) { return(GetEntitiesList(depend.WhereStatment, masterEntity.Id)); }
internal abstract void Execute(IDeleteCore core);
EntityDTO IDeleteInfo.GetSelfEntity(IDeleteCore core, uint id) { return(GetEntitiesList(core.UoW.Session.Connection, String.Format("WHERE {0}.id = @id", TableName), id)[0]); }
IList <EntityDTO> IDeleteInfo.GetDependEntities(IDeleteCore core, RemoveFromDependenceInfo depend, EntityDTO masterEntity) { throw new NotImplementedException(); }
IList <EntityDTO> IDeleteInfo.GetDependEntities(IDeleteCore core, ClearDependenceInfo depend, EntityDTO masterEntity) { return(GetEntitiesList(core.UoW.Session.Connection, depend.WhereStatment, masterEntity.Id)); }