CodedThought.Core.Data.MongoDb
1.0.0-alpha.2
See the version list below for details.
dotnet add package CodedThought.Core.Data.MongoDb --version 1.0.0-alpha.2
NuGet\Install-Package CodedThought.Core.Data.MongoDb -Version 1.0.0-alpha.2
<PackageReference Include="CodedThought.Core.Data.MongoDb" Version="1.0.0-alpha.2" />
<PackageVersion Include="CodedThought.Core.Data.MongoDb" Version="1.0.0-alpha.2" />
<PackageReference Include="CodedThought.Core.Data.MongoDb" />
paket add CodedThought.Core.Data.MongoDb --version 1.0.0-alpha.2
#r "nuget: CodedThought.Core.Data.MongoDb, 1.0.0-alpha.2"
#:package CodedThought.Core.Data.MongoDb@1.0.0-alpha.2
#addin nuget:?package=CodedThought.Core.Data.MongoDb&version=1.0.0-alpha.2&prerelease
#tool nuget:?package=CodedThought.Core.Data.MongoDb&version=1.0.0-alpha.2&prerelease
CodedThought.Core.Data.MongoDb
A .NET Core Data Entity Provider for MongoDB.
Requirements
MongoDb requires CodedThought.Core.Configuration and CodedThought.Core. These can be found in NuGet.
Usage
Install required packages. See requirements above.
Add the Database Connection settings in the appSetting.json or a custom .json file. The MongoDB connection string must include a database name, because the provider resolves the target database from the connection string.
{ "ConnectionString": "mongodb://localhost:27017/PeopleDb", "DatabaseType": "MongoDb" }Note: See CodedThought.Core.Configuration for JSON configuration specifications.
Add a new class and inherit from
CodedThought.Core.Data.GenericDataStoreController. Below is a sample class file.
using CodedThought.Core;
using CodedThought.Core.Data;
public class DataController : GenericDataStoreController {
public DataController(IMemoryCache cache, CodedThought.Core.Configuration.ConnectionSetting connectionSetting) {
DataStore = new GenericDataStore(cache, connectionSetting, string.Empty);
}
public Person GetPerson(string email) {
ParameterCollection param = DataStore.CreateParameterCollection();
param.AddStringParameter("EmailAddress", email);
return DataStore.Get<Person>(param);
}
public List<Person> GetPeople() => DataStore.GetMultiple<Person>(null);
}
using System.Data;
using CodedThought.Core;
using CodedThought.Core.Data;
/// <summary>
/// Person class used by the framework to locate the right collection and fields with class and property annotations.
/// </summary>
[DataTable("People")]
public class Person {
public Person() { }
[DataColumn("_id", DbType.String, DataColumnOptions.PrimaryKey)]
public string Id { get; set; }
[DataColumn("EmailAddress", DbType.String)]
public string EmailAddress { get; set; }
[DataColumn("FirstName", DbType.String)]
public string FirstName { get; set; }
[DataColumn("LastName", DbType.String)]
public string LastName { get; set; }
}
Note: MongoDB generates an
ObjectIdfor_id. Map it to astringproperty, as shown above. The provider writes the generated identifier back onto the entity afterAdd.
Behavior and Limitations
| Area | Behavior |
|---|---|
| Schema qualification | Collections are not schema qualified, so GetTableName returns the collection name unchanged and the default schema is ignored. |
| Row locking | EnableRowLocking is always false. MongoDB has no table hint equivalent. |
| Raw commands | CreateCommand throws NotSupportedException. Use Add, Get, Update and Remove. |
| Schema discovery | The table and view definition members throw NotImplementedException. MongoDB collections are schemaless, so the column list for a read is resolved from the returned documents. |
| SQL syntax helpers | Date and function syntax helpers that have no MongoDB equivalent throw NotImplementedException. |
| Transactions | BeginTransaction starts a MongoDB session. Multi document transactions require a replica set or a sharded cluster. |
Release Notes
1.0.0-alpha.1
| Feature | Description & Remarks |
|---|---|
| Restores and builds again | The unused Microsoft.Data.SqlClient reference was removed. It was the only cause of the NU1605 downgrade error, and no file in the project referenced SqlClient. |
One CodedThought.Core reference |
The configuration specific Choose/When blocks were removed in favor of a single ProjectReference, matching CodedThought.Core.Data.SqlServer. Debug and Release now compile against the same Core, and pack still emits CodedThought.Core as a package dependency. |
| Connection pooling is honored | MongoClient is now cached per connection string in a ConcurrentDictionary and shared by every connection instance, instead of being constructed on each open. The driver holds its connection pool inside the client, so the previous behavior created a new pool per operation. Call MongoDbConnection.ReleaseCachedClients() on application shutdown. |
| Connection reuse | OpenConnection reuses the held connection when it still matches the configured connection string, and only replaces it when the connection string changes. |
| Transactions reach the operations | MongoDbTransaction exposes its IClientSessionHandle, and Add, Get, GetDataSet, Update and Remove pass that session to the driver while a transaction is open. Previously the session was started and then ignored, so nothing took part in the transaction. |
| Transaction failures surface | Starting, committing and rolling back a transaction no longer swallow driver errors. A standalone deployment now raises CodedThoughtApplicationException instead of silently downgrading to unprotected writes. |
| Empty filters are rejected | Update and Remove throw CodedThoughtApplicationException when the parameters produce an empty filter. An empty MongoDB filter matches every document, so the previous behavior could update or delete an entire collection. |
| String primary keys are written back | Add now writes the generated _id back onto the entity for string mapped primary keys, alongside the existing numeric and Guid handling. IDBStore only sets integer and Guid keys, so the provider assigns the property named by the primary key attribute directly. |
| Data reader correctness | MongoDbDataReader bounds checks the current row, so reading before the first Read() or after the last row returns DBNull.Value instead of throwing. Read() no longer advances past the end of the result set. |
| Stable field types | GetFieldType resolves a column's type from the first non null value in the result set, rather than from the current row, so the type no longer changes as the reader advances. GetSchemaTable now reports ColumnSize, DataType, AllowDBNull and IsKey. |
| Null safe parameters | CreateParameter no longer unboxes a null extracted value. Every type case checks for null first. |
| Framework exception types | ApplicationException was replaced with Exceptions.CodedThoughtApplicationException throughout, and framework exceptions are rethrown rather than wrapped. The <BR> markup and ex.Source were removed from the Add failure message. |
TestConnection returns a result |
TestConnection and TestConnectionAsync return false on failure instead of propagating the connection exception. |
| Project file cleanup | The duplicate GeneratePackageOnBuild and PublishRepositoryUrl properties were removed, and the redundant ConnectionName override was dropped. |
Upgrade Notes
UpdateandRemovecalls that previously passed no filter parameters, and therefore affected the whole collection, now throw. Supply at least one filter parameter.- Applications that relied on transactions being silently ignored on a standalone MongoDB deployment
will now see an exception from
BeginTransaction. Use a replica set or remove the transaction. - Long running applications should call
MongoDbConnection.ReleaseCachedClients()during shutdown to dispose the cached clients.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- CodedThought.Core (>= 10.0.1.6)
- MongoDB.Driver (>= 3.10.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 |
|---|---|---|
| 1.0.0-beta.2 | 96 | 8/19/2026 |
| 1.0.0-alpha.2 | 38 | 10/22/2026 |
| 1.0.0-alpha.1 | 34 | 10/22/2026 |