Last active
August 29, 2015 14:09
-
-
Save jincod/2a48822ef46c01838c7d to your computer and use it in GitHub Desktop.
Refactoring Remove method in MongoDb Repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void RemoveById(Guid id) | |
{ | |
_collection.Remove(Query.EQ("_id", id)); | |
} | |
// Using | |
_repository.RemoveById(id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void RemoveByQuery(IMongoQuery query) | |
{ | |
_collection.Remove(query); | |
} | |
// Using | |
_repository.RemoveByQuery(Query.EQ("_id", id)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Remove<TValue>(Expression<Func<TEntity, TValue>> expression, TValue value) | |
{ | |
_collection.Remove(Query<TEntity>.EQ(expression, value)); | |
} | |
// Using | |
_repository.Remove(x => x.Id, id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Remove(Expression<Func<TEntity, bool>> whereExpression) | |
{ | |
_collection.Remove(Query<TEntity>.Where(whereExpression)); | |
} | |
// Using | |
_repository.Remove(x => x.Id == id); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment