TK.MongoDB.Repository.DistrubutedCollections 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package TK.MongoDB.Repository.DistrubutedCollections --version 1.0.1                
NuGet\Install-Package TK.MongoDB.Repository.DistrubutedCollections -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TK.MongoDB.Repository.DistrubutedCollections" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TK.MongoDB.Repository.DistrubutedCollections --version 1.0.1                
#r "nuget: TK.MongoDB.Repository.DistrubutedCollections, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TK.MongoDB.Repository.DistrubutedCollections as a Cake Addin
#addin nuget:?package=TK.MongoDB.Repository.DistrubutedCollections&version=1.0.1

// Install TK.MongoDB.Repository.DistrubutedCollections as a Cake Tool
#tool nuget:?package=TK.MongoDB.Repository.DistrubutedCollections&version=1.0.1                

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
  1. Default ConnectionStringSettingName is set to "MongoDocConnection", but this can be configured by calling the following static method:

    Settings.Configure("MongoDocConnection");
    
  2. 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);
    
  3. Default MasterCollectionName is set to "master", but this can be configured by calling the following static method:

    Settings.Configure(masterCollectionName: "master");
    
  4. 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.

  1. Find asynchronous (using Linq Expression.)

    Activity result = await ActivityRepository.FindAsync(CollectionId, x => x.Id == new ObjectId("5e36997898d2c15a400f8968"));
    
  2. 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);
    
  3. Insert asynchronous

    Activity activity = new Activity()
    {
        Text = "xyz",
        Client = 2,
        Caterer = 2
    };
    
    Activity result = await ActivityRepository.InsertAsync(activity);
    
  4. Update asynchronous

    Activity activity = new Activity()
    {
     Id = new ObjectId("5e36998998d2c1540ca23894"),
     Text = "Changed"
    };
    
    bool result = await ActivityRepository.UpdateAsync(CollectionId, activity);
    
  5. Delete asynchronous (by Id)

    bool result = await ActivityRepository.DeleteAsync(CollectionId, new ObjectId("5e36998998d2c1540ca23894"));
    
  6. Count asynchronous

    long result = await ActivityRepository.CountAsync(CollectionId);
    
  7. Exists asynchronous (using Linq Expression)

bool result = await ActivityRepository.ExistsAsync(CollectionId, x => x.Name == "abc");
Master Repository methods
  1. Get asynchronous

    var result = await MasterRepository.GetAsync();
    
  2. Get asynchronous (using dictionary of keys and values)

    Dictionary<string, object> keyValuePairs = new Dictionary<string, object>
    {
        { "Client", 1 }
    };
    
    var result = await MasterRepository.GetAsync(keyValuePairs);
    
  3. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 450 5/14/2020
1.1.2 488 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

New features and bug fixes