TK.MongoDB.Repository
1.0.2
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
<PackageReference Include="TK.MongoDB.Repository" Version="1.0.2" />
paket add TK.MongoDB.Repository --version 1.0.2
#r "nuget: TK.MongoDB.Repository, 1.0.2"
// 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
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);
Default
ConnectionStringSettingName
is set to "MongoDocConnection", but you can configure this by calling a static method as below:Settings.Configure(connectionStringSettingName: "MongoDocConnection");
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
Find (by Linq Expression)
Repository<Activity> repository = new Repository<Activity>(); Activity result = repository.FindAsync(x => x.Id == new ObjectId("5e36997898d2c15a400f8968")).Result;
Get (by Id)
Repository<Activity> repository = new Repository<Activity>(); Activity result = repository.GetAsync(new ObjectId("5e36997898d2c15a400f8968")).Result;
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;
Insert
Activity activity = new Activity() { Name = "abc" }; Repository<Activity> repository = new Repository<Activity>(); Activity result = repository.InsertAsync(activity).Result;
Update
Activity activity = new Activity() { Id = new ObjectId("5e36998998d2c1540ca23894"), Name = "abc3" }; Repository<Activity> repository = new Repository<Activity>(); bool result = repository.UpdateAsync(activity).Result;
Delete (by Id)
Repository<Activity> repository = new Repository<Activity>(); bool result = repository.DeleteAsync(new ObjectId("5e36998998d2c1540ca23894")).Result;
Count
Repository<Activity> repository = new Repository<Activity>(); long result = repository.CountAsync().Result;
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 | 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.1)
- SharpCompress (>= 0.24.0)
- System.Buffers (>= 4.5.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 |
---|---|---|
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