fixed various warnings
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MongoDB.Driver;
|
||||
using MongoDB.Driver.Linq;
|
||||
using MongoDbGenericRepository.DataAccess.Base;
|
||||
using MongoDbGenericRepository.Models;
|
||||
|
||||
namespace MongoDbGenericRepository.DataAccess.Create
|
||||
{
|
||||
/// <summary>
|
||||
/// A interface for adding documents to the Database and its Collections.
|
||||
/// </summary>
|
||||
public interface IMongoDbCreator : IDataAccessBase
|
||||
{
|
||||
/// <summary>
|
||||
@@ -57,50 +57,5 @@ namespace MongoDbGenericRepository.DataAccess.Create
|
||||
void AddMany<TDocument, TKey>(IEnumerable<TDocument> documents)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a IMongoQueryable for a potentially partitioned document type and a filter.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The document type.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key.</typeparam>
|
||||
/// <param name="filter">The filter definition.</param>
|
||||
/// <param name="partitionKey">The collection partition key.</param>
|
||||
/// <returns></returns>
|
||||
IMongoQueryable<TDocument> GetQuery<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collections for a potentially partitioned document type.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The document type.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key.</typeparam>
|
||||
/// <param name="document">The document.</param>
|
||||
/// <returns></returns>
|
||||
IMongoCollection<TDocument> HandlePartitioned<TDocument, TKey>(TDocument document)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collections for a potentially partitioned document type.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The document type.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key.</typeparam>
|
||||
/// <param name="partitionKey">The collection partition key.</param>
|
||||
/// <returns></returns>
|
||||
IMongoCollection<TDocument> HandlePartitioned<TDocument, TKey>(string partitionKey)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collections for the type TDocument with a partition key.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The document type.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key.</typeparam>
|
||||
/// <param name="partitionKey">The collection partition key.</param>
|
||||
/// <returns></returns>
|
||||
IMongoCollection<TDocument> GetCollection<TDocument, TKey>(string partitionKey = null)
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
using MongoDB.Driver;
|
||||
using MongoDB.Driver.Linq;
|
||||
using MongoDbGenericRepository.DataAccess.Base;
|
||||
using MongoDbGenericRepository.DataAccess.Base;
|
||||
using MongoDbGenericRepository.Models;
|
||||
using MongoDbGenericRepository.Utils;
|
||||
using System;
|
||||
@@ -69,25 +67,29 @@ namespace MongoDbGenericRepository.DataAccess.Create
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
if (!documents.Any())
|
||||
var documentsList = documents.ToList();
|
||||
|
||||
if (!documentsList.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (var document in documents)
|
||||
|
||||
foreach (var document in documentsList)
|
||||
{
|
||||
FormatDocument<TDocument, TKey>(document);
|
||||
}
|
||||
|
||||
// cannot use typeof(IPartitionedDocument).IsAssignableFrom(typeof(TDocument)), not available in netstandard 1.5
|
||||
if (documents.Any(e => e is IPartitionedDocument))
|
||||
if (documentsList.Any(e => e is IPartitionedDocument))
|
||||
{
|
||||
foreach (var group in documents.GroupBy(e => ((IPartitionedDocument)e).PartitionKey))
|
||||
foreach (var group in documentsList.GroupBy(e => ((IPartitionedDocument)e).PartitionKey))
|
||||
{
|
||||
await HandlePartitioned<TDocument, TKey>(group.FirstOrDefault()).InsertManyAsync(group.ToList(), null, cancellationToken);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await GetCollection<TDocument, TKey>().InsertManyAsync(documents.ToList(), null, cancellationToken);
|
||||
await GetCollection<TDocument, TKey>().InsertManyAsync(documentsList.ToList(), null, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,25 +104,29 @@ namespace MongoDbGenericRepository.DataAccess.Create
|
||||
where TDocument : IDocument<TKey>
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
if (!documents.Any())
|
||||
var documentList = documents.ToList();
|
||||
|
||||
if (!documentList.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (var document in documents)
|
||||
|
||||
foreach (var document in documentList)
|
||||
{
|
||||
FormatDocument<TDocument, TKey>(document);
|
||||
}
|
||||
|
||||
// cannot use typeof(IPartitionedDocument).IsAssignableFrom(typeof(TDocument)), not available in netstandard 1.5
|
||||
if (documents.Any(e => e is IPartitionedDocument))
|
||||
if (documentList.Any(e => e is IPartitionedDocument))
|
||||
{
|
||||
foreach (var group in documents.GroupBy(e => ((IPartitionedDocument)e).PartitionKey))
|
||||
foreach (var group in documentList.GroupBy(e => ((IPartitionedDocument)e).PartitionKey))
|
||||
{
|
||||
HandlePartitioned<TDocument, TKey>(group.FirstOrDefault()).InsertMany(group.ToList());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GetCollection<TDocument, TKey>().InsertMany(documents.ToList());
|
||||
GetCollection<TDocument, TKey>().InsertMany(documentList.ToList());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user