public Operation CreateDeleteOperation(EntityDTO masterEntity, DeleteDependenceInfo depend, IList <EntityDTO> dependEntities)
 {
     return(new HibernateDeleteOperation {
         ItemId = masterEntity.Id,
         DeletingItems = dependEntities
     });
 }
        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();
        }
        public DeleteInfoHibernate <TEntity> AddDeleteDependenceFromCollection(Expression <Func <TEntity, object> > propertyRefExpr)
        {
            string propName = PropertyUtil.GetName(propertyRefExpr);

            DeleteItems.Add(DeleteDependenceInfo.CreateFromCollection <TEntity>(propName));
            return(this);
        }
 public Operation CreateDeleteOperation(EntityDTO masterEntity, DeleteDependenceInfo depend, IList <EntityDTO> dependEntities)
 {
     return(new SQLDeleteOperation {
         ItemId = masterEntity.Id,
         TableName = TableName,
         WhereStatment = depend.WhereStatment
     });
 }
        public void AddDeleteDependence <ToClass> (DeleteDependenceInfo deleteDependence)
        {
            var info = ClassInfos.Find(i => i.ObjectClass == typeof(ToClass));

            if (info == null)
            {
                throw new InvalidOperationException(String.Format("Описание удаления для класса {0} не найдено.", typeof(ToClass)));
            }

            info.DeleteItems.Add(deleteDependence);
        }
 internal IDeleteInfo GetDeleteInfo(DeleteDependenceInfo deleteDependence)
 {
     if (deleteDependence.ObjectClass != null)
     {
         return(ClassInfos.Find(i => i.ObjectClass == deleteDependence.ObjectClass));
     }
     else
     {
         return(ClassInfos.OfType <DeleteInfo>().First(i => i.TableName == deleteDependence.TableName));
     }
 }
 IList <EntityDTO> IDeleteInfo.GetDependEntities(IDeleteCore core, DeleteDependenceInfo depend, EntityDTO masterEntity)
 {
     return(GetEntitiesList(core.UoW.Session.Connection, depend.WhereStatment, masterEntity.Id));
 }
 public DeleteInfoHibernate <TEntity> AddDeleteDependence(DeleteDependenceInfo info)
 {
     DeleteItems.Add(info);
     return(this);
 }
 public DeleteInfoHibernate <TEntity> AddDeleteCascadeDependence(Expression <Func <TEntity, object> > propertyRefExpr)
 {
     DeleteItems.Add(DeleteDependenceInfo.CreateFromParentPropery <TEntity> (propertyRefExpr));
     return(this);
 }
 public DeleteInfoHibernate <TEntity> AddDeleteDependence <TDependOn>(Expression <Func <TDependOn, object> > propertyRefExpr)
 {
     DeleteItems.Add(DeleteDependenceInfo.Create <TDependOn> (propertyRefExpr));
     return(this);
 }
Exemple #11
0
 IList <EntityDTO> IDeleteInfo.GetDependEntities(IDeleteCore core, DeleteDependenceInfo depend, EntityDTO masterEntity)
 {
     return(GetEntitiesList(depend.WhereStatment, masterEntity.Id));
 }