This commit is contained in:
David Lebee
2019-02-12 23:39:55 -05:00
parent 2bf96b1588
commit 581f17f448
7 changed files with 22 additions and 12 deletions
@@ -39,7 +39,7 @@ namespace PoweredSoft.ObjectStorage.MongoDB
protected virtual Expression<Func<TEntity, bool>> CreateEntityExpression(TEntity entity)
{
var objectKey = GetKeyProperty();
var objectKey = GetBsonIdProperty();
var constant = objectKey.GetValue(entity);
var expression = QueryableHelpers.CreateConditionExpression<TEntity>(objectKey.Name,
DynamicLinq.ConditionOperators.Equal, constant, DynamicLinq.QueryConvertStrategy.LeaveAsIs);
@@ -47,7 +47,7 @@ namespace PoweredSoft.ObjectStorage.MongoDB
return expression;
}
protected virtual PropertyInfo GetKeyProperty()
protected virtual PropertyInfo GetBsonIdProperty()
{
var objectKey = typeof(TEntity)
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
@@ -82,11 +82,19 @@ namespace PoweredSoft.ObjectStorage.MongoDB
public Task<TEntity> GetAsync(object key, CancellationToken cancellationToken = default(CancellationToken))
{
var keyProp = GetKeyProperty();
var keyProp = GetBsonIdProperty();
var expression = QueryableHelpers.CreateConditionExpression<TEntity>(keyProp.Name,
DynamicLinq.ConditionOperators.Equal, key, DynamicLinq.QueryConvertStrategy.LeaveAsIs);
var result = Collection.Find(expression).FirstOrDefaultAsync();
return result;
}
public List<PropertyInfo> GetObjectKeys()
{
return new List<PropertyInfo>()
{
GetBsonIdProperty()
};
}
}
}
@@ -5,9 +5,9 @@ using PoweredSoft.ObjectStorage.Core;
namespace PoweredSoft.ObjectStorage.MongoDB
{
public class MongoObjectStorageClient : IObjectStorageClient
public class MongoObjectStorageContext : IObjectStorageContext
{
public MongoObjectStorageClient(IMongoDatabase database)
public MongoObjectStorageContext(IMongoDatabase database)
{
Database = database;
}