Skip to content

Instantly share code, notes, and snippets.

@jincod
Last active August 29, 2015 14:09
Show Gist options
  • Save jincod/2a48822ef46c01838c7d to your computer and use it in GitHub Desktop.
Save jincod/2a48822ef46c01838c7d to your computer and use it in GitHub Desktop.
Refactoring Remove method in MongoDb Repository
public void RemoveById(Guid id)
{
_collection.Remove(Query.EQ("_id", id));
}
// Using
_repository.RemoveById(id);
public void RemoveByQuery(IMongoQuery query)
{
_collection.Remove(query);
}
// Using
_repository.RemoveByQuery(Query.EQ("_id", id));
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);
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