Пример #1
0
        public void RemoveRelation(IRelationById item, AbstractScopedCache repositoryScopedCache)
        {
            var sessionIdAsString = GetSessionId().ToString("n");

            using (DisposableTimer.TraceDuration <NhSessionHelper>("In RemoveRelation for session " + sessionIdAsString, "End RemoveRelation for session " + sessionIdAsString))
            {
                var relationType = GetOrCreateNodeRelationType(item.Type.RelationName, repositoryScopedCache);

                // Nh should handle this for us but got an error with mappings atm in SqlCe (APN 09/11/11)
                // Clear session cache to make sure it loads all of the tags in order to delete them all
                NhSession.Flush();

                // Clear the repository cache of this relation in case one has been added and then removed in the same unit of work
                var cacheKey = GenerateCacheKeyForRelation(item, relationType);
                repositoryScopedCache.InvalidateItems(cacheKey);

                var sourceIdValue      = (Guid)item.SourceId.Value;
                var destinationIdValue = (Guid)item.DestinationId.Value;

                var existingRelation = GetDbRelation(relationType.Alias, sourceIdValue, destinationIdValue).ToArray();

                if (existingRelation.Any())
                {
                    existingRelation.ForEach(x => NhSession.Delete(x));
                }
            }
        }
Пример #2
0
 /// <summary>
 /// 删除数据字典
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool Delete(D_Dictionary_Model model)
 {
     NHibernate.ITransaction tran = NhSession.BeginTransaction();
     try
     {
         NhSession.Delete(model);
         tran.Commit();
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         if (!tran.WasCommitted && !tran.WasRolledBack)
         {
             tran.Rollback();
         }
     }
 }