-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SqlPersistence with SqlTransport and EF (Core) #2
Comments
Hi @Tobias-Gr Yes, SQLPersistence should support this scenario. This is an integration tests that SQLPersistence works with SQL Transport by sharing the database connection and transaction. Yes, if you want to use EF for your data access you need to use the persistence session as described here. It is not enough to have the same connection string because sql persistence/will hold the connection during the handler execution. Two concurrent connections within the same transaction scope cause DTC escalation. |
thanks! Why is Outbox used in this sample although the persistence session is used? https://docs.particular.net/samples/outbox/sqltransport-sqlpersistence-ef/ |
Let me give you some examples how the persistence session works in different cases. I guess I should then move this to the documentation... Assumption: NServiceBus always requires a persistence to be configured so there is always some kind of synchronized storage session in the context. SQL Server Transport in native tx mode + NHibernate persistenceNot possible because NHibernate won't accept an externally created SQL Server Transport in TransactionScope mode + NHibernate persistenceTransport opens a SQL Server Transport in native tx mode + Outbox + NHibernate persistenceTransport opens and holds its SQL PersistnceSQL persistence works similarly to the NHibernate persistence but has the advantage of accepting an external |
Thanks, things begin to clear up.
As TransactionScope is the default for SqlTransport and session is reused for user data via EF: Why is outbox used/necessary in these samples?
In assumption of all data (transport, persistence, business) sharing one database this scenario makes sense for me only if my user data access technology is not able to reuse the session. Am I correct? Entity Framework Core
So SqlPersistence does not require TransactionScope in native mode? Would I be able to use EF Core with SqlPersistence in native mode? |
Small update regarding EF Core: In the NHibernate-TransactionScope-scenario I get an AmbientTransactionWarning-Exception in EF Core. If Outbox is enabled I don't get an exception in EF Core (but I don't know why). |
The recommended usage of SQL Server transport is either to:
Having a catalog/instance per endpoint (with both queues and user/saga data) is not a recommended design. The first option is good only for very small solutions. The second one requires either an outbox or DTC. Of these two Outbox is more easy of configure and performs better, that's why we used it in the samples. Using TransactionScope would be simpler though.
Using an external DbTransaction obtained from NHibernate context should work (as described in "Using external DbTransactions (relational databases only)" section). For this to work you need to enabled the outbox. This will put the transport in native transaction mode and NHibernate will also use its native transactions. TL;DR; it is OK to get the
When Outbox is enabled the SQL transport uses the native transaction. NHibernate probes for |
wow. sorry i missed this one. somehow i was not subscribed to notifications. @Tobias-Gr has @SzymonPobiega answered your questions? any other followups? @SzymonPobiega is there any of the above we should add to doco? |
Hi, |
Hi Simon,
I appreciate your efforts, very promising project!
Does SQLPersistence support the following scenario?
-Persistence: SqlPersistence (SQL Server)
-Transport: SqlTransport
-Business data: Entity Framework Core (on .net 4.61 runtime)
-all data in one database; no DTC, no Outbox but local/native single TransactionScope
If yes:
-Do I have to/Should I use SqlPersistenceSession (https://docs.particular.net/nservicebus/sql-persistence/ ) to get the context for the business data or is it sufficient to use the same connection string? Could you provide a sample how to use SqlPersistenceSession with EF Core?
-Why is Outbox used in this sample https://docs.particular.net/samples/outbox/sqltransport-sqlpersistence-ef/ ? In my understanding Outbox is not necessary because all data is in one database.
Thanks!
Tobias
The text was updated successfully, but these errors were encountered: