support insertion of documents with different PartitionKey values
This commit is contained in:
1 parent
456af09a84
commit
7f126a098d
3 files changed
+27
-24
No files matched your search
@@ -183,7 +183,18 @@ namespace MongoDbGenericRepository
|
||||
{
|
||||
FormatDocument<TDocument, TKey>(document);
|
||||
}
|
||||
HandlePartitioned<TDocument, TKey>(documents.FirstOrDefault()).InsertMany(documents.ToList());
|
||||
// cannot use typeof(IPartitionedDocument).IsAssignableFrom(typeof(TDocument)), not available in netstandard 1.5
|
||||
if (documents.Any(e => e is IPartitionedDocument))
|
||||
{
|
||||
foreach (var group in documents.GroupBy(e => ((IPartitionedDocument)e).PartitionKey))
|
||||
{
|
||||
HandlePartitioned<TDocument, TKey>(group.FirstOrDefault()).InsertMany(group.ToList());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GetCollection<TDocument, TKey>().InsertMany(documents.ToList());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user