Skip to content

Commit

Permalink
feat: implement execute update
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikoo-Asadnejad committed Sep 27, 2024
1 parent a5dbb73 commit 412b9e2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Linq.Expressions;
using GenericRepository.Domain;
using Microsoft.EntityFrameworkCore.Query;

namespace GenericRepository.Application.Interfaces.GenericRepository.Command;

Expand All @@ -17,5 +18,7 @@ public partial interface IRepository<T> where T : BaseEntity
Task DeleteRangeAsync(IEnumerable<T> models);
Task SoftDeleteRangeAsync(IEnumerable<T> models);
Task ExecuteDeleteAsync(Expression<Func<T, bool>> condition);
Task ExecuteUpdateAsync(Expression<Func<T, bool>> condition , Expression<Func<SetPropertyCalls<T>, SetPropertyCalls<T>>> updateExpression);
Task ExecuteUpdateAsync(Expression<Func<SetPropertyCalls<T>, SetPropertyCalls<T>>> updateExpression);

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;

namespace GenericRepository.Application.Interfaces.GenericRepository.Command;
Expand All @@ -17,4 +18,7 @@ public partial interface IRepository<T>
void DeleteRange(IEnumerable<T> models);
void ClearChangeTracker();
void ExecuteDelete(Expression<Func<T, bool>> condition);
void ExecuteUpdate(Expression<Func<T, bool>> condition,
Expression<Func<SetPropertyCalls<T>, SetPropertyCalls<T>>> updateExpression);
void ExecuteUpdate(Expression<Func<SetPropertyCalls<T>, SetPropertyCalls<T>>> updateExpression);
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,17 @@ await _model.Where(condition)
.ExecuteDeleteAsync();
}













public async Task ExecuteUpdateAsync(Expression<Func<T, bool>> condition,
Expression<Func<SetPropertyCalls<T>, SetPropertyCalls<T>>> updateExpression)
{
await _model.Where(condition)
.ExecuteUpdateAsync(updateExpression);
}

public async Task ExecuteUpdateAsync(Expression<Func<SetPropertyCalls<T>, SetPropertyCalls<T>>> updateExpression)
{
await _model.ExecuteUpdateAsync(updateExpression);
}

}

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq.Expressions;
using GenericRepository.Domain;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Storage;

namespace GenericRepository.Infrastructure.Repository.GenericRepository.Command;
Expand Down Expand Up @@ -57,5 +58,17 @@ public void ExecuteDelete(Expression<Func<T, bool>> condition)
_model.Where(condition)
.ExecuteDelete();
}

public void ExecuteUpdate(Expression<Func<T, bool>> condition,
Expression<Func<SetPropertyCalls<T>, SetPropertyCalls<T>>> updateExpression)
{
_model.Where(condition)
.ExecuteUpdate(updateExpression);
}

public void ExecuteUpdate(Expression<Func<SetPropertyCalls<T>, SetPropertyCalls<T>>> updateExpression)
{
_model.ExecuteUpdate(updateExpression);
}

}

0 comments on commit 412b9e2

Please sign in to comment.