TK.MongoDB.Repository 1.0.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package TK.MongoDB.Repository --version 1.0.6
NuGet\Install-Package TK.MongoDB.Repository -Version 1.0.6
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" Version="1.0.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TK.MongoDB.Repository --version 1.0.6
#r "nuget: TK.MongoDB.Repository, 1.0.6"
#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 as a Cake Addin
#addin nuget:?package=TK.MongoDB.Repository&version=1.0.6

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

TK.MongoDB.Repository

Repository pattern implementation (using linq) of MongoDB in .NET Framework

Usage

Settings
  1. Default ConnectionStringSettingName is set to "MongoDocConnection", but you can configure this by calling a static method as below:

    Settings.Configure("MongoDocConnection");
    
  2. you can configure ExpiryAfterSeconds index for a specific collection by calling a static method as below:

    Settings.Configure<Activity>(2592000);
    
  3. Example:

    public class RepoUnitTest
    {
        Repository<Activity> ActivityRepository;
        public RepoUnitTest()
        {
            Settings.Configure("MongoDocConnection");
            Settings.Configure<Activity>(2592000);
            ActivityRepository = new Repository<Activity>();
        }
    
     //.... other methods and properties
    }
    
Models

Create a document model implementing $BaseEntity$ to use in repository. The name of this model will be used as collection name in MongoDB.

public class Activity : BaseFile<ObjectId>
{
    public string Name { get; set; }
}
Repository methods
  1. Find asynchronous (using Linq Expression.)

    Activity result = ActivityRepository.FindAsync(x => x.Id == new ObjectId("5e36997898d2c15a400f8968")).Result;
    
  2. Get asynchronous (by Id)

    Activity result = ActivityRepository.GetAsync(new ObjectId("5e36997898d2c15a400f8968")).Result;
    
  3. Get asynchronous (using Linq Expression.)

    Has paged records in a Tuple<IEnumerable<T>, long> of records and total count.

    var result = ActivityRepository.GetAsync(1, 10, x => x.Name.Contains("abc") && x.Deleted == false).Result;
    Console.WriteLine($"Output:\nTotal: {result.Item2}\n{JToken.Parse(JsonConvert.SerializeObject(result.Item1)).ToString(Formatting.Indented)}");
    
  4. Get synchronous (using Linq Expression.)

    Has nonpaged records.

    var result = ActivityRepository.Get(x => x.Name.Contains("abc") && x.Deleted == false);
    
  5. In synchronous (Get by IN filter. Nonpaged records)

    List<string> names = new List<string> { "abc", "def", "ghi" };
    var result = ActivityRepository.In(x => x.Name, names);
    
  6. Insert asynchronous

    Activity activity = new Activity()
    {
        Name = "abc"
    };
    
    Activity result = ActivityRepository.InsertAsync(activity).Result;
    
  7. Update asynchronous

    Activity activity = new Activity()
    {
     Id = new ObjectId("5e36998998d2c1540ca23894"),
     Name = "abc3"
    };
    
    bool result = ActivityRepository.UpdateAsync(activity).Result;
    
  8. Delete asynchronous (by Id)

    bool result = ActivityRepository.DeleteAsync(new ObjectId("5e36998998d2c1540ca23894")).Result;
    
  9. Count asynchronous

    long result = ActivityRepository.CountAsync().Result;
    
  10. Exists asynchronous (using Linq Expression)

bool result = ActivityRepository.ExistsAsync(x => x.Name == "abc").Result;
Tests

Refer to TK.MongoDB.Test project for all Unit Tests.

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
2.1.6 1,495 8/29/2022
2.1.5 982 1/17/2022
2.1.4 1,876 6/21/2021
2.1.3 1,003 2/24/2021
2.1.2 1,429 10/13/2020
2.1.1 1,162 8/20/2020
2.1.0 941 8/20/2020
1.0.10 1,006 8/16/2020
1.0.9 872 8/11/2020
1.0.8 971 8/10/2020
1.0.7 1,317 6/11/2020
1.0.6 1,043 2/5/2020
1.0.5 1,049 2/5/2020
1.0.4 908 2/4/2020
1.0.3 954 2/3/2020
1.0.2 1,043 2/2/2020

Get all and In methods added to repository