Created
October 16, 2017 14:08
-
-
Save fasetto/765aaea4a672ae78e381c6a51e339a0b to your computer and use it in GitHub Desktop.
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 virtual async Task<IEnumerable<TEntity>> GetByFieldAsync(string field, string value) | |
{ | |
var filter = Builders<TEntity>.Filter.Eq(field, value); | |
var result = await Collection.Find(filter).ToListAsync(); | |
return result; | |
} | |
public virtual async Task<TEntity> GetByIdAsync(ObjectId id) | |
{ | |
var filter = Builders<TEntity>.Filter.Eq("_id", id); | |
var entity = await Collection.Find(filter).FirstOrDefaultAsync(); | |
return entity; | |
} | |
public virtual async Task<long> DeleteAllAsync() | |
{ | |
var filter = new BsonDocument(); | |
var result = await Collection.DeleteManyAsync(filter); | |
return result.DeletedCount; | |
} | |
public virtual async Task<bool> UpdateAsync(ObjectId id, string field, string value) | |
{ | |
var update = Builders<TEntity>.Update.Set(field, value); | |
var result = await Collection.UpdateOneAsync(u => u.Id == id, update); | |
return result.ModifiedCount != 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment