TK.MongoDB.Repository 1.0.2

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.2                
NuGet\Install-Package TK.MongoDB.Repository -Version 1.0.2                
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.2" />                
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.2                
#r "nuget: TK.MongoDB.Repository, 1.0.2"                
#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.2

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

TK.MongoDB.Repository

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

Usage

Settings
  1. Default expireAfterSeconds is set to 2592000 seconds or 30 days, but you can configure this by calling a static method as below:

    Settings.Configure(2592000);
    
  2. Default ConnectionStringSettingName is set to "MongoDocConnection", but you can configure this by calling a static method as below:

    Settings.Configure(connectionStringSettingName: "MongoDocConnection");
    
  3. You can also set both of the settings as below:

    Settings.Configure(2592000, "MongoDocConnection");
    
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 (by Linq Expression)

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

    Repository<Activity> repository = new Repository<Activity>();
    Activity result = repository.GetAsync(new ObjectId("5e36997898d2c15a400f8968")).Result;
    
  3. Get (by Linq Expression)

    Repository<Activity> repository = new Repository<Activity>();
    var result = repository.GetAsync(1, 10, x => x.Name.Contains("abc") && x.Deleted == false).Result;
    
  4. Insert

    Activity activity = new Activity()
    {
        Name = "abc"
    };
    
    Repository<Activity> repository = new Repository<Activity>();
    Activity result = repository.InsertAsync(activity).Result;
    
  5. Update

    Activity activity = new Activity()
    {
     Id = new ObjectId("5e36998998d2c1540ca23894"),
     Name = "abc3"
    };
    
    Repository<Activity> repository = new Repository<Activity>();
    bool result = repository.UpdateAsync(activity).Result;
    
  6. Delete (by Id)

    Repository<Activity> repository = new Repository<Activity>();
    bool result = repository.DeleteAsync(new ObjectId("5e36998998d2c1540ca23894")).Result;
    
  7. Count

    Repository<Activity> repository = new Repository<Activity>();
    long result = repository.CountAsync().Result;
    
  8. Exists (by Linq Expression)

    Repository<Activity> repository = new Repository<Activity>();
    bool result = repository.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,946 8/29/2022
2.1.5 1,008 1/17/2022
2.1.4 1,996 6/21/2021
2.1.3 1,028 2/24/2021
2.1.2 1,453 10/13/2020
2.1.1 1,212 8/20/2020
2.1.0 964 8/20/2020
1.0.10 1,047 8/16/2020
1.0.9 911 8/11/2020
1.0.8 1,001 8/10/2020
1.0.7 1,343 6/11/2020
1.0.6 1,109 2/5/2020
1.0.5 1,119 2/5/2020
1.0.4 944 2/4/2020
1.0.3 1,000 2/3/2020
1.0.2 1,063 2/2/2020

Initial release