CodedThought.Core.Data.MongoDb 1.0.0-alpha.1

This is a prerelease version of CodedThought.Core.Data.MongoDb.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package CodedThought.Core.Data.MongoDb --version 1.0.0-alpha.1
                    
NuGet\Install-Package CodedThought.Core.Data.MongoDb -Version 1.0.0-alpha.1
                    
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="CodedThought.Core.Data.MongoDb" Version="1.0.0-alpha.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CodedThought.Core.Data.MongoDb" Version="1.0.0-alpha.1" />
                    
Directory.Packages.props
<PackageReference Include="CodedThought.Core.Data.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 CodedThought.Core.Data.MongoDb --version 1.0.0-alpha.1
                    
#r "nuget: CodedThought.Core.Data.MongoDb, 1.0.0-alpha.1"
                    
#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 CodedThought.Core.Data.MongoDb@1.0.0-alpha.1
                    
#: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=CodedThought.Core.Data.MongoDb&version=1.0.0-alpha.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=CodedThought.Core.Data.MongoDb&version=1.0.0-alpha.1&prerelease
                    
Install as a Cake Tool

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

  1. Install required packages. See requirements above.

  2. 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.

  3. 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 ObjectId for _id. Map it to a string property, as shown above. The provider writes the generated identifier back onto the entity after Add.

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
  • Update and Remove calls 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 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. 
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.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