Beispiel #1
0
 /// <summary>
 /// Deletes an entity.
 /// </summary>
 /// <param name="entity">The entity to delete.</param>
 /// <returns>The number of items affected.</returns>
 public int Delete(T entity)
 {
     _Mutex.WaitOne();
     try
     {
         //delete by identity
         int identityOrdinal = _Aspect.IdentityOrdinal;
         if (identityOrdinal >= 0)
         {
             object identityValue = _Aspect[identityOrdinal].GetValue(entity);
             if (!ValidationHelper.IsNullOrEmpty(identityValue))
             {
                 return(_Engine.Delete(_Aspect, new ClassFilterTerm(_Aspect, identityOrdinal, identityValue)));
             }
         }
         //delete by unique member
         foreach (int uniqueOrdinal in _Aspect.UniqueMemberOrdinals)
         {
             object uniqueValue = _Aspect[uniqueOrdinal].GetValue(entity);
             if (!ValidationHelper.IsNullOrEmpty(uniqueValue))
             {
                 return(_Engine.Delete(_Aspect, new ClassFilterTerm(_Aspect, uniqueOrdinal, uniqueValue)));
             }
         }
         //has primary keys
         if (_Aspect.HasPrimaryKey)
         {
             return(_Engine.Delete(_Aspect, _Aspect.CreatePrimaryKeyFilter(entity)));
         }
         else
         {
             //can't delete
             throw new ArgumentException("Unable to find members to delete " + _Aspect, "entity");
         }
     }
     finally
     {
         _Mutex.ReleaseMutex();
     }
 }
 /// <summary>
 /// Executes the delete.
 /// </summary>
 /// <returns>The number of items affected.</returns>
 public int Delete()
 {
     return(_Storage.Delete(this._Aspect, this._WhereFirst));
 }