I've just confirmed this in the test I've pasted into bottom of mail.
Without wanting to sound ignorant; Does anyone know what is the reason we
must call BeginTransaction() ? I was of the understanding that NHibernate
integrates with TransactionScope, so why the need to explicitly invoke an
NHibernate transaction?
Regards,
John.
[Test]
public void TestTransaction()
{
var session = /* fluffy stuff to get a session */;
session.FlushMode = FlushMode.Auto;
using (new TransactionScope())
using (var trans = session.BeginTransaction()) // remove this, and it
fails on the Query()
{
try
{
var marketSegment =
session.Query<DataClasses.MarketSegment>().Single(each => each.Code ==
"BP");
var id = session.Save(new DataClasses.ClientAccount { AccountCode =
"XX123", MarketSegment = marketSegment });
var clientAccount = session.Get<DataClasses.ClientAccount>(id);
Assert.That(clientAccount, Is.Not.Null, "Get failed");
clientAccount =
session.Query<DataClasses.ClientAccount>().SingleOrDefault(each =>
each.AccountCode == "XX123");
Assert.That(clientAccount, Is.Not.Null, "Query failed");
}
finally
{
trans.Rollback();
}
}
}
On Wednesday, April 11, 2012 9:27:29 AM UTC+1, Gunnar Liljas wrote:
>
> Yes, I believe it is.
>
> /G
>
> 2012/4/10 John T
>
>> Is this necessary within a TransactionScope?
>>
>> Thanks,
>> J.
>>
>> On Tuesday, April 10, 2012 8:12:48 PM UTC+1, Gunnar Liljas wrote:
>>
>>> You may need an explicit transaction (BeginTransaction) for autoflushing
>>> to work as expected.
>>>
>>> /G
>>>
>>> 2012/4/10 John T
>>>
>>>> Hi,
>>>>
>>>> Yes, I have executed the code exactly as written - and it does not
>>>> work. Sequence contains no elements on the Single(). :)
>>>>
>>>> Regards,
>>>> John.
>>>>
>>>> On Tuesday, April 10, 2012 5:15:16 PM UTC+1, Oskar Berggren wrote:
>>>>>
>>>>> Den 10 april 2012 16:27 skrev John Thornborrow:
>>>>>
>>>>> > Hi,
>>>>> >
>>>>> > We are using Automatic flush mode, but it is very explicitly and
>>>>> precisely
>>>>> > not flushing when we query. The code example I posted in my previous
>>>>> post is
>>>>> > factually correct, the second line (i.e. query) will/does throw an
>>>>> > exception.
>>>>> >
>>>>> > Cannot viably use Get()/Load() because the Query is composed further
>>>>> up the
>>>>> > chain, thus the Law of Demeter kicks in and well.. it's pretty ugly
>>>>> for the
>>>>> > domain to know what is and isn't a concern of the DB anyway. :)
>>>>> >
>>>>> > Though I must ask.. why implement a Cache if it is not going to be
>>>>> > Queryable?
>>>>>
>>>>>
>>>>> The L1 cache is more like the "working data set" - it contains the
>>>>> objects currently tracked by the session. This has multiple purposes:
>>>>> avoiding object duplication, knowing which objects to persist when
>>>>> flushing changes, and performance. NH relies on the database to
>>>>> execute queries, returned objects may still come from the L1 cache if
>>>>> they were already loaded.
>>>>>
>>>>>
>>>>> Regarding the oversimplified code example you gave, have you executed
>>>>> that code exactly as written?
>>>>>
>>>>>
>>>>> /Oskar
>>>>>
>>>>
>>>> On Tuesday, April 10, 2012 5:15:16 PM UTC+1, Oskar Berggren wrote:
>>>>>
>>>>> Den 10 april 2012 16:27 skrev John Thornborrow:
>>>>>
>>>>> > Hi,
>>>>> >
>>>>> > We are using Automatic flush mode, but it is very explicitly and
>>>>> precisely
>>>>> > not flushing when we query. The code example I posted in my previous
>>>>> post is
>>>>> > factually correct, the second line (i.e. query) will/does throw an
>>>>> > exception.
>>>>> >
>>>>> > Cannot viably use Get()/Load() because the Query is composed further
>>>>> up the
>>>>> > chain, thus the Law of Demeter kicks in and well.. it's pretty ugly
>>>>> for the
>>>>> > domain to know what is and isn't a concern of the DB anyway. :)
>>>>> >
>>>>> > Though I must ask.. why implement a Cache if it is not going to be
>>>>> > Queryable?
>>>>>
>>>>>
>>>>> The L1 cache is more like the "working data set" - it contains the
>>>>> objects currently tracked by the session. This has multiple purposes:
>>>>> avoiding object duplication, knowing which objects to persist when
>>>>> flushing changes, and performance. NH relies on the database to
>>>>> execute queries, returned objects may still come from the L1 cache if
>>>>> they were already loaded.
>>>>>
>>>>>
>>>>> Regarding the oversimplified code example you gave, have you executed
>>>>> that code exactly as written?
>>>>>
>>>>>
>>>>> /Oskar
>>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "nhusers" group.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msg/nhusers/-/uraL59S5BY8J.
>>>>
>>>> To post to this group, send email to [email protected].
>>>> To unsubscribe from this group, send email to
>>>> [email protected].
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/nhusers?hl=en.
>>>>
>>>
>>> --
>> You received this message because you are subscribed to the Google Groups
>> "nhusers" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/nhusers/-/jZYrwqvtmT0J.
>>
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/nhusers?hl=en.
>>
>
>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/nhusers/-/tAkw-ya_VhIJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.