JCode.ORMX.DbProvider.MongoDB 1.2.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package JCode.ORMX.DbProvider.MongoDB --version 1.2.2
                    
NuGet\Install-Package JCode.ORMX.DbProvider.MongoDB -Version 1.2.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="JCode.ORMX.DbProvider.MongoDB" Version="1.2.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JCode.ORMX.DbProvider.MongoDB" Version="1.2.2" />
                    
Directory.Packages.props
<PackageReference Include="JCode.ORMX.DbProvider.MongoDB" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add JCode.ORMX.DbProvider.MongoDB --version 1.2.2
                    
#r "nuget: JCode.ORMX.DbProvider.MongoDB, 1.2.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.
#:package JCode.ORMX.DbProvider.MongoDB@1.2.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=JCode.ORMX.DbProvider.MongoDB&version=1.2.2
                    
Install as a Cake Addin
#tool nuget:?package=JCode.ORMX.DbProvider.MongoDB&version=1.2.2
                    
Install as a Cake Tool

JCode.ORMX.DbProvider.MongoDB

MongoDB 数据库提供程序,用于 JCode.ORMX 框架。

快速开始

安装

Install-Package JCode.ORMX.DbProvider.MongoDB

基本用法

using JCode.ORMX.DbProvider.MongoDB;
using JCode.ORMX.Attributes;
using MongoDB.Bson;

// 定义实体
[Table("Users")]
public class User
{
    [Column(IsPrimaryKey = true)]
    public ObjectId Id { get; set; }
    
    [Column]
    public string Name { get; set; }
    
    [Column]
    public string Email { get; set; }
}

// 初始化
using var provider = new MongoDbProvider("mongodb://localhost:27017/MyDb");
var tableManager = provider.GetTableManager();

// 创建集合
tableManager.Create(typeof(User));

// CRUD 操作
var table = tableManager.Table<User>();

// 插入
var user = table.Insert(new User { Name = "John", Email = "john@example.com" });

// 查询
var users = table.Where(u => u.Name == "John").GetList();

// 更新
table.Update(u => u.Email, "newemail@example.com");

// 删除指定实体
table.Delete(user);

// 或使用条件删除
table.Where(u => u.Id == userId).Delete();

功能特性

  • ✅ 完整的 MongoDB 支持
  • ✅ 类型安全的 LINQ 查询
  • ✅ 事务支持
  • ✅ 批量操作(InsertAll/UpdateAll/DeleteAll)
  • ✅ 连接池管理
  • ✅ 参数化查询(防 SQL 注入)
  • ✅ 智能 SQL 调试

链式查询

ORMX 提供流畅的链式查询 API:

// 复杂查询
var result = table
    .Where(u => u.Age > 18)
    .OrderByDesc(u => u.CreatedAt)
    .Limit(10)
    .GetList();

// 聚合查询
var count = table.Count();
var maxAge = table.Max(u => u.Age);

SQL 调试

// 查看生成的 SQL
table.Extension((extObj) =>
{
    Console.WriteLine($"SQL: {extObj.Query}");
    Console.WriteLine($"参数:{string.Join(", ", extObj.Parameters)}");
})
.Where(u => u.Age > 25)
.GetList();

配置选项

连接字符串

// 简单连接
var provider = new MongoDbProvider("mongodb://localhost:27017/MyDb");

// 带认证连接
var provider = new MongoDbProvider("mongodb://username:password@localhost:27017/MyDb");

// 副本集
var provider = new MongoDbProvider("mongodb://node1:27017,node2:27017/MyDb?replicaSet=rs0");

高级配置

var settings = new MongoClientSettings
{
    Server = new MongoServerAddress("localhost", 27017),
    ConnectTimeout = TimeSpan.FromSeconds(30),
    SocketTimeout = TimeSpan.FromSeconds(30),
    MaxConnectionPoolSize = 100,
    MinConnectionPoolSize = 10
};

var client = new MongoClient(settings);
var provider = new MongoDbProvider(client.GetDatabase("MyDb"));

📖 完整手册

详细使用文档请访问:ORMX 完整使用手册

手册包含:

  • 高级查询(聚合、连接、子查询、分组)
  • 事务管理最佳实践
  • Redis 缓存集成
  • 分布式数据库支持(分片、读写分离)
  • 性能优化建议
  • 完整 API 参考
  • 故障排除指南

依赖项

  • MongoDB.Driver (2.x+)
  • JCode.ORMX (1.0.0+)
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.4 94 5/4/2026
1.2.2 102 4/20/2026