You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update Step 1 to explain that:
- Each UseSqlServer(connectionString) creates a NEW connection object
- Matching connection strings signal the adapter to attempt coordination
- Adapter uses UseTransaction() to coordinate separate connection objects
- Transaction sharing works because SQL Server supports coordination at DB level
This addresses the misconception that same connection string = same connection
object. Instead, the adapter coordinates SEPARATE connection objects via
UseTransaction() when the connection strings match.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
Copy file name to clipboardExpand all lines: MULTI_CONTEXT_USAGE_GUIDE.md
+15-7Lines changed: 15 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,35 +20,43 @@ Multi-context support allows you to store different Casbin policy types in separ
20
20
21
21
Create separate `CasbinDbContext` instances for different storage locations.
22
22
23
-
**⚠️ IMPORTANT for transaction guarantees:** To ensure atomic operations across contexts:
24
-
1. All contexts must use the **same connection string** (same database)
25
-
2. The database must support `UseTransaction()` to share a physical connection object
26
-
3.**Same connection string alone is not enough** - the database must be able to coordinate transactions
23
+
**⚠️ CRITICAL - Transaction Guarantees:**
24
+
25
+
The adapter detects transaction compatibility by comparing connection strings. If connection strings match, it will attempt to use `UseTransaction()` to coordinate transactions. However:
26
+
27
+
-**Matching connection strings** tell the adapter to TRY sharing transactions
28
+
-**Actual transaction sharing** depends on the database's ability to coordinate via `UseTransaction()`
29
+
- SQL Server, PostgreSQL, MySQL can share transactions when contexts connect to the **same database**
30
+
- SQLite can share transactions only when contexts use the **same physical file**
27
31
28
32
**Example: SQL Server with different schemas**
29
33
30
34
```csharp
31
35
usingMicrosoft.EntityFrameworkCore;
32
36
usingCasbin.Persist.Adapter.EFCore;
33
37
34
-
// Define connection string once - REQUIRED for atomic transactions
0 commit comments