AI agents: use the documentation index at llms.txt to locate machine-readable pages. This section is indexed by https://docs.particular.net/transports/llms.txt. The markdown version of this page is served as plain text. An MCP server at /mcp serves the same content via the search_docs and read_doc tools; it is read-only and needs no credentials. Markdown versions of documentation pages are available by appending .md to the page URL. Directory URLs use index.md. They are served as text/plain because some retrieval backends reject text/markdown.

Using the SQL Server transport with Entity Framework

Target Version:
NServiceBus 10.x

To avoid escalating transactions to the Distributed Transaction Coordinator (DTC), operations using Entity Framework must share their connection string with the SQL Server transport.

However, Entity Framework cannot directly use the connection string for the SQL Server transport when using the Database/Model First approach. In this case, Entity Framework requires a special connection string containing specific metadata.

The metadata can be added using EntityConnectionStringBuilder. The modified connection string can then be used to create an EntityConnection, which can then be used to create an instance of the generated DbContext type:

var entityBuilder = new EntityConnectionStringBuilder
{
    Provider = "System.Data.SqlClient",
    ProviderConnectionString = "the database connection string",
    Metadata = "res://*/MySample.csdl|res://*/MySample.ssdl|res://*/MySample.msl"
};

var entityConn = new EntityConnection(entityBuilder.ToString());

using (var mySampleContainer = new MySampleContainer(entityConn))
{
    // use the DbContext as required
}

The DbContext generated Entity Framework does not have a constructor with an EntityConnection, but since it is a partial class, the constructor can be added:

partial class MySampleContainer
{
    public MySampleContainer(EntityConnection dbConnection)
        : base(dbConnection, true)
    {
    }
}