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

            DeleteItems.Add(DeleteDependenceInfo.CreateFromCollection <TEntity>(propName));
            return(this);
        }
Пример #4
0
 public Operation CreateDeleteOperation(EntityDTO masterEntity, DeleteDependenceInfo depend, IList <EntityDTO> dependEntities)
 {
     return(new SQLDeleteOperation {
         ItemId = masterEntity.Id,
         TableName = TableName,
         WhereStatment = depend.WhereStatment
     });
 }
Пример #5
0
        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);
        }
Пример #6
0
 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));
     }
 }
Пример #7
0
 IList <EntityDTO> IDeleteInfo.GetDependEntities(IDeleteCore core, DeleteDependenceInfo depend, EntityDTO masterEntity)
 {
     return(GetEntitiesList(core.UoW.Session.Connection, depend.WhereStatment, masterEntity.Id));
 }
Пример #8
0
 public DeleteInfoHibernate <TEntity> AddDeleteDependence(DeleteDependenceInfo info)
 {
     DeleteItems.Add(info);
     return(this);
 }
Пример #9
0
 public DeleteInfoHibernate <TEntity> AddDeleteCascadeDependence(Expression <Func <TEntity, object> > propertyRefExpr)
 {
     DeleteItems.Add(DeleteDependenceInfo.CreateFromParentPropery <TEntity> (propertyRefExpr));
     return(this);
 }
Пример #10
0
 public DeleteInfoHibernate <TEntity> AddDeleteDependence <TDependOn>(Expression <Func <TDependOn, object> > propertyRefExpr)
 {
     DeleteItems.Add(DeleteDependenceInfo.Create <TDependOn> (propertyRefExpr));
     return(this);
 }
Пример #11
0
 IList <EntityDTO> IDeleteInfo.GetDependEntities(IDeleteCore core, DeleteDependenceInfo depend, EntityDTO masterEntity)
 {
     return(GetEntitiesList(depend.WhereStatment, masterEntity.Id));
 }