TK.MongoDB.Repository.DistrubutedCollections
1.0.0
See the version list below for details.
dotnet add package TK.MongoDB.Repository.DistrubutedCollections --version 1.0.0
NuGet\Install-Package TK.MongoDB.Repository.DistrubutedCollections -Version 1.0.0
<PackageReference Include="TK.MongoDB.Repository.DistrubutedCollections" Version="1.0.0" />
paket add TK.MongoDB.Repository.DistrubutedCollections --version 1.0.0
#r "nuget: TK.MongoDB.Repository.DistrubutedCollections, 1.0.0"
// Install TK.MongoDB.Repository.DistrubutedCollections as a Cake Addin #addin nuget:?package=TK.MongoDB.Repository.DistrubutedCollections&version=1.0.0 // Install TK.MongoDB.Repository.DistrubutedCollections as a Cake Tool #tool nuget:?package=TK.MongoDB.Repository.DistrubutedCollections&version=1.0.0
TK.MongoDB.Repository.DistCollections
Repository pattern implementation with distributed collections of MongoDB in .NET Framework
Intro
This solution provides a simple and easy way to create distributed collections based on specified properties in a model. You may also use nested levels of collections by keeping a backlink in the source collection.
A master collection, created by default, acts as an reference index to all the collections stored. Master collection maintains the creation date and update date of each record, you may also name a collection if needed.
Usage
Configure Settings
Default
ConnectionStringSettingName
is set to "MongoDocConnection", but this can be configured by calling the following static method:Settings.Configure("MongoDocConnection");
Default
ExpiryAfterSeconds
index is set to "15778463" (approx: 6 months), but this can be configured by calling the following static method:Settings.Configure(expireAfterSeconds: 2592000);
Default
MasterCollectionName
is set to "master", but this can be configured by calling the following static method:Settings.Configure(masterCollectionName: "master");
Example:
public class MessageUnitTest { Repository<Activity> ActivityRepository; public MessageUnitTest() { Settings.Configure("MongoDocConnection"); ActivityRepository = new Repository<Activity>(); } //.... other methods and properties }
Creating Models
The solution has a predefined attribute Distribute
with an optional value of Level
, adding the attribute triggers the collection distribution based on the property.
Providing Level
makes logical nesting of collections by keeping backlinks, for example in the model below the first entry with Caterer, Client and Order defined will be added to source collection and subsequent entries added to a new collection created. In this way the source collection will always have an entry to corelate with the nested collection.
Creating a document model implementing $BaseEntity$ to use in repository.
public class Message : BaseEntity<ObjectId>
{
[BsonRequired]
public string Text { get; set; }
[Distribute]
public long Caterer { get; set; }
[Distribute]
public long Client { get; set; }
[Distribute(Level = 1)]
public long? Order { get; set; }
}
Repository methods
<u>Collection Ids</u> can be fetched using Master Repository and needs to be defined for each method in repository, hence, each call may run on a different collection altogether.
Find asynchronous (using Linq Expression.)
Activity result = await ActivityRepository.FindAsync(CollectionId, x => x.Id == new ObjectId("5e36997898d2c15a400f8968"));
Get asynchronous (using Linq Expression.)
Has paged records in a
Tuple<IEnumerable<T>, long>
of records and total count.var result = await ActivityRepository.GetAsync(1, 10, x => x.Name.Contains("abc") && x.Deleted == false);
Insert asynchronous
Activity activity = new Activity() { Text = "xyz", Client = 2, Caterer = 2 }; Activity result = await ActivityRepository.InsertAsync(activity);
Update asynchronous
Activity activity = new Activity() { Id = new ObjectId("5e36998998d2c1540ca23894"), Text = "Changed" }; bool result = await ActivityRepository.UpdateAsync(CollectionId, activity);
Delete asynchronous (by Id)
bool result = await ActivityRepository.DeleteAsync(CollectionId, new ObjectId("5e36998998d2c1540ca23894"));
Count asynchronous
long result = await ActivityRepository.CountAsync(CollectionId);
Exists asynchronous (using Linq Expression)
bool result = await ActivityRepository.ExistsAsync(CollectionId, x => x.Name == "abc");
Master Repository methods
Get asynchronous
var result = await MasterRepository.GetAsync();
Get asynchronous (using dictionary of keys and values)
Dictionary<string, object> keyValuePairs = new Dictionary<string, object> { { "Client", 1 } }; var result = await MasterRepository.GetAsync(keyValuePairs);
Update asynchronous
bool result = await MasterRepository.UpdateAsync("53df73c45d7e493b86746066a693534c", "Untitled-3");
Tests
Refer to TK.MongoDB.Test project for <u>Unit Tests</u> for:
- Repository
- Master Repository
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
- MongoDB.Driver (>= 2.10.4)
- Newtonsoft.Json (>= 12.0.3)
- SharpCompress (>= 0.25.0)
- System.Buffers (>= 4.5.1)
- System.Numerics.Vectors (>= 4.5.0)
- System.Runtime.CompilerServices.Unsafe (>= 4.7.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.2.7 | 758 | 6/17/2020 |
1.2.6 | 476 | 6/16/2020 |
1.2.5 | 442 | 6/15/2020 |
1.2.4 | 456 | 6/15/2020 |
1.2.3 | 515 | 6/14/2020 |
1.2.2 | 550 | 6/4/2020 |
1.2.1 | 507 | 5/20/2020 |
1.2.0 | 494 | 5/20/2020 |
1.1.9 | 469 | 5/19/2020 |
1.1.8 | 498 | 5/17/2020 |
1.1.7 | 501 | 5/17/2020 |
1.1.6 | 489 | 5/17/2020 |
1.1.5 | 458 | 5/15/2020 |
1.1.4 | 473 | 5/15/2020 |
1.1.3 | 452 | 5/14/2020 |
1.1.2 | 490 | 5/13/2020 |
1.1.1 | 444 | 5/13/2020 |
1.1.0 | 449 | 5/13/2020 |
1.0.2 | 462 | 5/12/2020 |
1.0.1 | 448 | 5/12/2020 |
1.0.0 | 439 | 5/12/2020 |
Package uploaded