I also tried this, but without success. The problem is different. I
make changes within the domain layer and query from repositories while
the TransactionScope/SessionScope/UoW is maintained in the application
layer.

This would be ok, but doesn't work:
using (new TransactionScope())
 {
    Foo foo = ActiveRecordMediator<Foo>.FindFirst();
    foo.Bar = 2;
    Assert.AreEqual(1,ActiveRecordMediator<Foo>.Count(Expression.Eq("Bar",2)));
 } //commits here

This works, but is not ok for me:
using (new TransactionScope())
 {
    Foo foo = ActiveRecordMediator<Foo>.FindFirst();
    foo.Bar = 2;
 } //commits here
Assert.AreEqual(1,ActiveRecordMediator<Foo>.Count(Expression.Eq("Bar",2)));

The latter example is a problem because the application might
determine later to rollback the transaction, perhaps because another
domain object throws an exception.

-Markus

On 8/26/08, Simon Laroche <[EMAIL PROTECTED]> wrote:
>
> I think it has to do with nh 2.0 now requiring a transaction.
> Therefore, you should use a transaction scope in your tests.  However,
> using a transaction scope changes the flush mode of the session to
> FlushMode.Commit. Your test should look like this:
>
>  using (new TransactionScope())
>  {
>     Foo foo = ActiveRecordMediator<Foo>.FindFirst();
>     foo.Bar = 2;
>  } //commits here
>
> Assert.AreEqual(1,ActiveRecordMediator<Foo>.Count(Expression.Eq("Bar",2)));
> }
>
> I'm not sure why the flush mode of the session gets changed to commit.
> Maybe someone with a better understanding then mine would know
>
>
> Simon
>
>
> Le 08-08-25 à 10:13, "Markus Zywitza" <[EMAIL PROTECTED]> a
> écrit :
>
> >
> > Hi all
> >
> > I'm not sure where the problem lies, but I have massive problems when
> > I have locally edited objects, that there is no flush before those
> > objects are queried from database by another method.
> >
> > Example
> >
> > using (new SessionScope()){
> >  Foo foo = ActiveRecordMediator<Foo>.FindFirst();
> >  foo.Bar = 2;
> >
> >  Assert.AreEqual(1,ActiveRecordMediator<Foo>.Count(Expression.Eq
> > ("Bar",2)));
> > }
> >
> > This example fails. When I read the NH docs correctly, NH should check
> > for changes to a foo before querying for other Foos and hence flush
> > automatically.
> >
> > This is a contrived example. In my production code, I have currently a
> > lot of such calls in my repositories:
> >
> > Foo[] GetFooByBar(int bar) {
> >  SessionScope.Current.Flush();
> >  return ActiveRecordMediator.FindAll(Expression.Eq("Bar",bar));
> > }
> >
> > I don't like that workaround. Any comments on what I might be doing
> > wrong here?
> >
> > -Markus
> >
> > >
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
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/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to