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

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