Skip to content

Commit

Permalink
feat: implement truncate table
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikoo-Asadnejad committed Sep 27, 2024
1 parent 412b9e2 commit c9ea29c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ public partial interface IRepository<T> where T : BaseEntity
Task ExecuteUpdateAsync(Expression<Func<T, bool>> condition , Expression<Func<SetPropertyCalls<T>, SetPropertyCalls<T>>> updateExpression);
Task ExecuteUpdateAsync(Expression<Func<SetPropertyCalls<T>, SetPropertyCalls<T>>> updateExpression);

Task TruncateTableAsync();

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ public partial interface IRepository<T>
void ExecuteUpdate(Expression<Func<T, bool>> condition,
Expression<Func<SetPropertyCalls<T>, SetPropertyCalls<T>>> updateExpression);
void ExecuteUpdate(Expression<Func<SetPropertyCalls<T>, SetPropertyCalls<T>>> updateExpression);
void TruncateTable();
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,10 @@ public async Task ExecuteUpdateAsync(Expression<Func<SetPropertyCalls<T>, SetPro
await _model.ExecuteUpdateAsync(updateExpression);
}

public async Task TruncateTableAsync()
{
var tableName = _context.Model.FindEntityType(typeof(T)).GetTableName();
await _context.Database.ExecuteSqlRawAsync($"TRUNCATE TABLE {tableName}");
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,9 @@ public void ExecuteUpdate(Expression<Func<SetPropertyCalls<T>, SetPropertyCalls<
_model.ExecuteUpdate(updateExpression);
}

public void TruncateTable()
{
var tableName = _context.Model.FindEntityType(typeof(T)).GetTableName();
_context.Database.ExecuteSqlRaw($"TRUNCATE TABLE {tableName}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ public async Task RollbackTransactionAsync()
public async Task CommitTransactionAsync()
=> await _context.Database.CommitTransactionAsync();


}

0 comments on commit c9ea29c

Please sign in to comment.