jeudi 3 août 2017

EF Repository - Custom Remove Method

I've created a generic EF repository. For every deletions I need to check if my entity has a specific interface and do some changes to some other entities before remove it. How would I do that?

I tried to crate a foreach like this but it's not working.

var entitiesToRemove = context.Set<TEntity>().Where(predicate).ToList();

foreach (var entityToRemove in entitiesToRemove)
{
    ///
}

My current remove method

public void Remove(Func<TEntity, bool> predicate)
{
    context.Set<TEntity>()
        .Where(predicate).ToList()
        .ForEach(del => context.Set<TEntity>().Remove(del));
}





Aucun commentaire:

Enregistrer un commentaire