This is a guess, but doesn't .Enumerable<Strategy>() delay the
(complete) execution until the enumeration is actually enumerated?
This would then happen after the transaction is closed.

/Oskar


2010/10/28 Michael Delva <[email protected]>:
> Hello all,
>
> I've just changed the implementations of the methods of my
> repositories to encapsulate them all in a transaction:
>
>
> public class Repository<TEntity> : IRepository<TEntity>
>    where TEntity : BaseEntity<TEntity>
> {
>    public Repository(ISession session)
>    {
>        Session = session;
>    }
>
>    public ISession Session { get; set; }
>
>    private static Type ConcreteType { get { return
> typeof(TEntity); } }
>
>    protected TResult Transact<TResult>(Func<TResult> func)
>    {
>        if (!Session.Transaction.IsActive)
>        {
>            // Wrap in transaction
>            TResult result;
>
>            using (var tx = Session.BeginTransaction())
>            {
>                result = func.Invoke();
>                tx.Commit();
>            }
>            return result;
>        }
>        // Don't wrap;
>        return func.Invoke();
>    }
>
>    protected void Transact(Action action)
>    {
>        Transact(() =>
>                    {
>                        action.Invoke();
>                        return false;
>                    });
>    }
> }
>
> I use this like that:
>
> public IEnumerable<Strategy> AllStrategiesSortedByName(StrategyType
> type)
> {
>    return Transact(() => Session.CreateQuery("from Strategy s where
> s.Type = :strategyType order by s.Name")
>                                .SetParameter("strategyType", type)
>                                .Enumerable<Strategy>());
> }
>
> With the above query, I have this exception:
>
> NHibernate.TransactionException: Commit failed with SQL exception
>
> InnerException : System.Data.SQLite.SQLiteException: SQLite error -
> cannot commit transaction - SQL statements in progress
>
> If I remove the transaction, all runs fine. If I replace the HQL query
> with a QueryOver query, it works fine too.
>
> Would you have any ideas?
>
> Thanks in advance
>
> Mike
>
> --
> You received this message because you are subscribed to the Google Groups 
> "nhusers" 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/nhusers?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" 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/nhusers?hl=en.

Reply via email to