One good thing NHibernate has is ability to map multiples entities to same table without using inheritance too.
Example: for restaurant BoundedContext
:
public class RestaurantCustomer
{
public int Id;
public string Name;
}
For inventory BoundedContext
:
InventoryCustomer
{
public int Id;
public string Name;
}
We can map both these entities to the same database table Customer
.
EF Core requires two different DbContext
to achieve this and automatically uses distributed transaction in the background.
Does NHibernate also use distributed transaction in the background, or is it supported without using distributed transaction?
TLDR: No, NHibernate will not use a distributed transaction to work with this mapping.
EF Core requires two different
DbContext
to achieve this and automatically uses distributed transaction in the background.
I highly doubt that is EF doing. More likely the application uses a transaction scope while interacting with both db contexts, with each db context using its own connection. So, two connections get enlisted in the same transaction scope, which can only result into escalating the transaction to distributed.
That is not the responsibility of EF. That is the responsibility of the application. Maybe there is a way to provide the connection to use to EF in order to have both db contexts using the same connection and avoid the scope escalation to distributed while using both contexts in the same scope, but I am not using EF since long, so, I do not know.
Does NHibernate also use distributed transaction in the background, or is it supported without using distributed transaction?
NHibernate does not use distributed transaction by itself. It only enlists the connection it uses in the ambient scope if any. (And this can be disabled.) Like with EF, the scope will escalate to distributed if this results in more than one connection enlisted in it. That is also the responsibility of the application to handle its scope in a way that avoids enlisting two connections in the scope, if distributed transactions are undesired.
As long as you use only one session per scope, without any other thing that may be considered as a durable resource by System.Transactions (which mainly consists of database connections), the scope will not be escalated to distributed, whatever the mappings you have used with NHibernate.
Whatever the mapping, NHibernate uses only one connection per session to query the database. (On top of that, instead of letting NHibernate handle the connection, you can provide your own.) So, no, mapping many entities to the same table will not cause NHibernate to escalate to distributed.