Пример #1
0
        internal void Delete(int id, string entityName)
        {
            IEntitySchema es     = IEntitySchemaHelper.Get(entityName);
            object        entity = es.CreateInstance();

            entity.SetPropertyValue(es.KeyName, id);
            this.GenericHelper.Delete(entity);
        }
Пример #2
0
        public void MMSave(Type entityType, int parentId, string parentEntityName, List <string> childIds)
        {
            IOperationManager opm     = new DefaultOperationManager(this._context, this._currentUser);
            IEntitySchema     es      = IEntitySchemaHelper.Get(entityType);
            IEntitySchema     schema2 = IEntitySchemaHelper.Get(parentEntityName);
            object            entity  = this._context.FindById(schema2.EntityType, new object[] { parentId });

            if (entity == null)
            {
                throw new DeleteException(es, parentId, string.Format("父实体[{0}]记录不存在", parentEntityName));
            }
            opm.AUD_OperationCheck(schema2, entity, EntityOperationEnum.Update);
            string        str        = string.Format("{0}s", es.EntityName);
            string        entityName = schema2.MmTables[str];
            IEntitySchema schema3    = IEntitySchemaHelper.Get(entityName);
            string        condition  = string.Format("{0} = {1}", schema2.KeyName, parentId);
            IList         list       = this._context.Where(schema3.EntityType, condition, new DbParameter[0]);
            List <int>    first      = (from o in childIds select o.ToInt()).ToList <int>();
            List <int>    second     = new List <int>();

            foreach (object obj3 in list)
            {
                int item = (int)obj3.GetPropertyValue(es.KeyName, null);
                second.Add(item);
            }
            List <int> list4 = first.Except <int>(second).ToList <int>();

            using (TransactionScope scope = new TransactionScope())
            {
                foreach (int num in list4)
                {
                    object targetObj = schema3.CreateInstance();
                    targetObj.SetPropertyValue(schema3.KeyName, this.GetNextIdentity(), null);
                    targetObj.SetPropertyValue(schema2.KeyName, parentId, null);
                    targetObj.SetPropertyValue(es.KeyName, num, null);
                    this._context.Insert(targetObj);
                }
                scope.Complete();
            }
        }