You're welcome - is it working with two databases at the same time, or
are they alternative datastores where it'll work with one of them in a
particular instance?
If it's the first case, then cross-DB integrity is a thorny issue that I
haven't got sufficient experience of - DTC would be the obvious first
port of call, but I don't know if SQLite supports DTC nor am I familiar
with DTC + NHibernate. In the second case, the pattern I use [in an
ASP.NET MVC application] is to inject an ISession into my controller
class throught my IoC container, explicitly begin a transaction at the
start of a unit-of-work and commit / rollback at the end - there are
lots of other patterns that people use though, and I'm not saying that
this is the "right" way of doing it. For example (omiting
boring-but-important details such as parameter validation)...
public class UnitOfWork {
private ISession _nhSession;
public UnitOfWork(ISession nhSession) {
_nhSession = nhSession;
}
public T Execute<T>(Func<T> workload)
{
using(var tran = _nhSession.BeginTransaction()) {
var retVal = workload();
tran.Commit();
return retVal;
}
}
}
class FooController : ControllerBase // : MVC4 controller
protected UnitOfWork UoW { get; private set; }
protected IFooBusinessLogic FooLogic { get; private set; }
public FooController(UnitOfWork workUnit, IFooBusinessLogic
fooLogic) { ... }
public FooModel Get(int id) {
Foo foo = null;
try {
foo = UoW.Execute(() => this.FooLogic.Get(id));
}
catch(Exception ex) {
HandleError(ex);
// Builds up a set of errors
}
return CreateResult(AutoMapper.Mapper.Map<FooModel>(foo));
// CreateResult<T> returns an object of form { bool: success, T:
payload, error[]: errors }
}
}
The error handling in this code is suspect, I think that the error
collection belongs with the UnitOfWork but that is a currently
unresolved issue.
/Pete
From: [email protected] [mailto:[email protected]] On
Behalf Of Paulson Mathew
Sent: 08 April 2013 12:43
To: [email protected]
Subject: Re: [nhusers] NHibernate connection.isolation settings is not
used while establishing a connection to the database
Hi Pete
Thanks for the update.... our application deals with two databases
SQLite and SQL Server. The application needs to be configured so as to
work with both these databases. With the proposed solution, could you
please let me know how we could proceed given the above situation?
Actually I am a newbie :)
Thanks
Paulson
On Friday, April 5, 2013 6:12:28 PM UTC+5:30, PeteA wrote:
Hi,
The standard approach would be to ensure that all DB access occurs in an
explicit transaction; relying on implicit transactions isn't generally
regarded as good practice, and can be dangerous (because they're handled
on a per-statement level, not per-batch). I'd therefore encourage you to
use explicit transactions, in which case you'll get the behaviour you
expect.
If you really don't want to use explicit transactions for some reason
then I /think/ you could provide an IInterceptor which overrides
SetSession () and issues the appropriate SQL commands. That feels very
kludgy to me though.
/Pete
From: [email protected] <javascript:>
[mailto:[email protected] <javascript:> ] On Behalf Of Paulson
Mathew
Sent: 05 April 2013 06:15
To: [email protected] <javascript:>
Subject: [nhusers] NHibernate connection.isolation settings is not used
while establishing a connection to the database
Hi,
I have created a .net application, which using NHibernate 2.1.0.4000 to
connect with SQL server and the configuration is given as below.
<nhibernate xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property
name="connection.provider">NHibernate.Connection.DriverConnectionProvide
r</property>
<property
name="connection.driver_class">NHibernate.Driver.SqlClientDriver</proper
ty>
<property
name="connection.connection_string">Server=(local);database=MYDB;Integra
ted Security=SSPI;</property>
<property
name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
<property name="show_sql">false</property>
<property
name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactor
yFactory, NHibernate.ByteCode.Castle</property>
<!-- Specifying the default schema improves the query execution
plan generated by SQL server -->
<property name="default_schema">dbo</property>
<property name="connection.isolation">ReadUncommitted</property>
<!-- Specifying the 2nd level cache -->
<property
name="cache.provider_class">NHibernate.Caches.SysCache.SysCacheProvider,
NHibernate.Caches.SysCache</property>
<property name="cache.use_second_level_cache">true</property>
<property name="cache.use_query_cache" >true</property>
<mapping assembly="MyAssemply" />
</session-factory>
</nhibernate>
In Nhibernate configuration, the isolation level is specified as
ReadUncommitted .But isolation level is not used while establishing a
connection to the database. Instead it's taking the default isolation
level as ReadCommitted to proceed.
Doing some investigation its observed that if session.BeginTransaction()
is specified in the code then isolation level is taken as the configured
value. Is there any way to connect database with isolation level as
"ReadUncommitted" (or isolation level from the settings) without setting
session.BeginTransaction().
Please share thoughts.
--
You received this message because you are subscribed to the Google
Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected] <javascript:> .
To post to this group, send email to [email protected]
<javascript:> .
Visit this group at http://groups.google.com/group/nhusers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google
Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.