From 78096e6d5302f7b888050cbd404565182a670316 Mon Sep 17 00:00:00 2001 From: ITMAGINATION Date: Mon, 20 Oct 2014 15:15:50 +0200 Subject: [PATCH 1/5] NH3727 unittest showing bug --- .../NHSpecificTest/NH3727/Entity.cs | 7 ++ .../NHSpecificTest/NH3727/FixtureByCode.cs | 93 +++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 src/NHibernate.Test/NHSpecificTest/NH3727/Entity.cs create mode 100644 src/NHibernate.Test/NHSpecificTest/NH3727/FixtureByCode.cs diff --git a/src/NHibernate.Test/NHSpecificTest/NH3727/Entity.cs b/src/NHibernate.Test/NHSpecificTest/NH3727/Entity.cs new file mode 100644 index 00000000000..af7cf52808b --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/NH3727/Entity.cs @@ -0,0 +1,7 @@ +namespace NHibernate.Test.NHSpecificTest.NH3727 +{ + class Entity + { + public virtual int Id { get; set; } + } +} \ No newline at end of file diff --git a/src/NHibernate.Test/NHSpecificTest/NH3727/FixtureByCode.cs b/src/NHibernate.Test/NHSpecificTest/NH3727/FixtureByCode.cs new file mode 100644 index 00000000000..8cd42d9c1b5 --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/NH3727/FixtureByCode.cs @@ -0,0 +1,93 @@ +using System.Collections.Generic; +using System.Linq; +using NHibernate.Cfg.MappingSchema; +using NHibernate.Criterion; +using NHibernate.Impl; +using NHibernate.Mapping.ByCode; +using NHibernate.Transform; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.NH3727 +{ + public class ByCodeFixture : TestCaseMappingByCode + { + protected override HbmMapping GetMappings() + { + var mapper = new ModelMapper(); + mapper.Class(rc => + { + rc.Id(x => x.Id); + }); + + return mapper.CompileMappingForAllExplicitlyAddedEntities(); + } + + [Test] + public void QueryOverWithSubqueryProjectionCanBeExecutedMoreThanOnce() + { + using (ISession session = OpenSession()) + using (session.BeginTransaction()) + { + const int parameter1 = 111; + + var countSubquery = QueryOver.Of() + .Where(x => x.Id == parameter1) //any condition which makes output SQL has parameter + .Select(Projections.RowCount()) + ; + + var originalQueryOver = session.QueryOver() + .SelectList(l => l + .Select(x => x.Id) + .SelectSubQuery(countSubquery) + ) + .TransformUsing(Transformers.ToList); + + originalQueryOver.List(); + + Assert.DoesNotThrow(() => originalQueryOver.List(), "Second try to execute QueryOver thrown exception."); + } + } + + [Test] + public void ClonedQueryOverExecutionMakesOriginalQueryOverNotWorking() + { + // Projections are copied by clone operation. + // SubqueryProjection use SubqueryExpression which holds CriteriaQueryTranslator (class SubqueryExpression { private CriteriaQueryTranslator innerQuery; }) + // So given CriteriaQueryTranslator is used twice. + // Since CriteriaQueryTranslator has CollectedParameters collection, second execution of the Criteria does not fit SqlCommand parameters. + + using (ISession session = OpenSession()) + using (session.BeginTransaction()) + { + const int parameter1 = 111; + + var countSubquery = QueryOver.Of() + .Where(x => x.Id == parameter1) //any condition which makes output SQL has parameter + .Select(Projections.RowCount()) + ; + + var originalQueryOver = session.QueryOver() + //.Where(x => x.Id == parameter2) + .SelectList(l => l + .Select(x => x.Id) + .SelectSubQuery(countSubquery) + ) + .TransformUsing(Transformers.ToList); + + var clonedQueryOver = originalQueryOver.Clone(); + clonedQueryOver.List(); + + Assert.DoesNotThrow(() => originalQueryOver.List(), "Cloned QueryOver execution caused source QueryOver throw exception when executed."); + } + } + + private static IEnumerable GetProjectionList(IQueryOver clonedQueryOver) + { + var projectionList = (((CriteriaImpl)clonedQueryOver.RootCriteria).Projection as ProjectionList); + for (int i = 0; i < projectionList.Length; i++) + { + yield return projectionList[i]; + } + } + } +} \ No newline at end of file From d181f6cef086d6e719e2392e2927fef88d973493 Mon Sep 17 00:00:00 2001 From: ITMAGINATION Date: Mon, 20 Oct 2014 15:16:32 +0200 Subject: [PATCH 2/5] NH3727 bugfix proposition --- .../Criterion/SubqueryExpression.cs | 260 +++++++++--------- 1 file changed, 130 insertions(+), 130 deletions(-) diff --git a/src/NHibernate/Criterion/SubqueryExpression.cs b/src/NHibernate/Criterion/SubqueryExpression.cs index 017e67e8973..924a2ac7c11 100644 --- a/src/NHibernate/Criterion/SubqueryExpression.cs +++ b/src/NHibernate/Criterion/SubqueryExpression.cs @@ -10,134 +10,134 @@ namespace NHibernate.Criterion { - [Serializable] - public abstract class SubqueryExpression : AbstractCriterion - { - private readonly CriteriaImpl criteriaImpl; - private readonly String quantifier; - private readonly bool prefixOp; - private readonly String op; - private QueryParameters parameters; - private IType[] types; - - [NonSerialized] private CriteriaQueryTranslator innerQuery; - - protected SubqueryExpression(String op, String quantifier, DetachedCriteria dc) - :this(op, quantifier, dc, true) - { - } - - protected SubqueryExpression(String op, String quantifier, DetachedCriteria dc, bool prefixOp) - { - criteriaImpl = dc.GetCriteriaImpl(); - this.quantifier = quantifier; - this.prefixOp = prefixOp; - this.op = op; - } - - public IType[] GetTypes() - { - return types; - } - - protected abstract SqlString ToLeftSqlString(ICriteria criteria, ICriteriaQuery outerQuery); - - public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary enabledFilters) - { - InitializeInnerQueryAndParameters(criteriaQuery); - - if (innerQuery.HasProjection == false) - { - throw new QueryException("Cannot use subqueries on a criteria without a projection."); - } - - ISessionFactoryImplementor factory = criteriaQuery.Factory; - - IOuterJoinLoadable persister = (IOuterJoinLoadable)factory.GetEntityPersister(criteriaImpl.EntityOrClassName); - - //patch to generate joins on subqueries - //stolen from CriteriaLoader - CriteriaJoinWalker walker = - new CriteriaJoinWalker(persister, innerQuery, factory, criteriaImpl, criteriaImpl.EntityOrClassName, enabledFilters); - - parameters = innerQuery.GetQueryParameters(); // parameters can be inferred only after initialize the walker - - SqlString sql = walker.SqlString; - - if (criteriaImpl.FirstResult != 0 || criteriaImpl.MaxResults != RowSelection.NoValue) - { - int? offset = Loader.Loader.GetOffsetUsingDialect(parameters.RowSelection, factory.Dialect); - int? limit = Loader.Loader.GetLimitUsingDialect(parameters.RowSelection, factory.Dialect); - Parameter offsetParameter = offset.HasValue ? innerQuery.CreateSkipParameter(offset.Value) : null; - Parameter limitParameter = limit.HasValue ? innerQuery.CreateTakeParameter(limit.Value) : null; - sql = factory.Dialect.GetLimitString(sql, offset, limit, offsetParameter, limitParameter); - } - - // during CriteriaImpl.Clone we are doing a shallow copy of each criterion. - // this is not a problem for common criterion but not for SubqueryExpression because here we are holding the state of inner CriteriaTraslator (ICriteriaQuery). - // After execution (ToSqlString) we have to clean the internal state because the next execution may be performed in a different tree reusing the same istance of SubqueryExpression. - innerQuery = null; - - SqlStringBuilder buf = new SqlStringBuilder().Add(ToLeftSqlString(criteria, criteriaQuery)); - if (op != null) - { - buf.Add(" ").Add(op).Add(" "); - } - - if (quantifier != null && prefixOp) - { - buf.Add(quantifier).Add(" "); - } - - buf.Add("(").Add(sql).Add(")"); - - if (quantifier != null && prefixOp == false) - { - buf.Add(" ").Add(quantifier); - } - - return buf.ToSqlString(); - } - - public override string ToString() - { - if(prefixOp) - return string.Format("{0} {1} ({2})", op, quantifier, criteriaImpl); - - return string.Format("{0} ({1}) {2}", op, criteriaImpl, quantifier); - } - - public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery) - { - return parameters.NamedParameters.Values.ToArray(); - } - - public override IProjection[] GetProjections() - { - return null; - } - - public void InitializeInnerQueryAndParameters(ICriteriaQuery criteriaQuery) - { - if (innerQuery == null) - { - ISessionFactoryImplementor factory = criteriaQuery.Factory; - - innerQuery = new CriteriaQueryTranslator( - factory, - criteriaImpl, //implicit polymorphism not supported (would need a union) - criteriaImpl.EntityOrClassName, - criteriaQuery.GenerateSQLAlias(), - criteriaQuery); - - types = innerQuery.HasProjection ? innerQuery.ProjectedTypes : null; - } - } - - public ICriteria Criteria - { - // NH-1146 - get { return criteriaImpl; } - } - } + [Serializable] + public abstract class SubqueryExpression : AbstractCriterion + { + private readonly CriteriaImpl criteriaImpl; + private readonly String quantifier; + private readonly bool prefixOp; + private readonly String op; + private QueryParameters parameters; + private IType[] types; + + [NonSerialized] private CriteriaQueryTranslator innerQuery; + + protected SubqueryExpression(String op, String quantifier, DetachedCriteria dc) + : this(op, quantifier, dc, true) + { + } + + protected SubqueryExpression(String op, String quantifier, DetachedCriteria dc, bool prefixOp) + { + criteriaImpl = dc.GetCriteriaImpl(); + this.quantifier = quantifier; + this.prefixOp = prefixOp; + this.op = op; + } + + public IType[] GetTypes() + { + return types; + } + + protected abstract SqlString ToLeftSqlString(ICriteria criteria, ICriteriaQuery outerQuery); + + public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary enabledFilters) + { + InitializeInnerQueryAndParameters(criteriaQuery, true); // Force reinitialization. There can be old instance from earlier Criteria execution or cloned Criteria. + + if (innerQuery.HasProjection == false) + { + throw new QueryException("Cannot use subqueries on a criteria without a projection."); + } + + ISessionFactoryImplementor factory = criteriaQuery.Factory; + + IOuterJoinLoadable persister = (IOuterJoinLoadable)factory.GetEntityPersister(criteriaImpl.EntityOrClassName); + + //patch to generate joins on subqueries + //stolen from CriteriaLoader + CriteriaJoinWalker walker = + new CriteriaJoinWalker(persister, innerQuery, factory, criteriaImpl, criteriaImpl.EntityOrClassName, enabledFilters); + + parameters = innerQuery.GetQueryParameters(); // parameters can be inferred only after initialize the walker + + SqlString sql = walker.SqlString; + + if (criteriaImpl.FirstResult != 0 || criteriaImpl.MaxResults != RowSelection.NoValue) + { + int? offset = Loader.Loader.GetOffsetUsingDialect(parameters.RowSelection, factory.Dialect); + int? limit = Loader.Loader.GetLimitUsingDialect(parameters.RowSelection, factory.Dialect); + Parameter offsetParameter = offset.HasValue ? innerQuery.CreateSkipParameter(offset.Value) : null; + Parameter limitParameter = limit.HasValue ? innerQuery.CreateTakeParameter(limit.Value) : null; + sql = factory.Dialect.GetLimitString(sql, offset, limit, offsetParameter, limitParameter); + } + + // during CriteriaImpl.Clone we are doing a shallow copy of each criterion. + // this is not a problem for common criterion but not for SubqueryExpression because here we are holding the state of inner CriteriaTraslator (ICriteriaQuery). + // After execution (ToSqlString) we have to clean the internal state because the next execution may be performed in a different tree reusing the same istance of SubqueryExpression. + innerQuery = null; + + SqlStringBuilder buf = new SqlStringBuilder().Add(ToLeftSqlString(criteria, criteriaQuery)); + if (op != null) + { + buf.Add(" ").Add(op).Add(" "); + } + + if (quantifier != null && prefixOp) + { + buf.Add(quantifier).Add(" "); + } + + buf.Add("(").Add(sql).Add(")"); + + if (quantifier != null && prefixOp == false) + { + buf.Add(" ").Add(quantifier); + } + + return buf.ToSqlString(); + } + + public override string ToString() + { + if (prefixOp) + return string.Format("{0} {1} ({2})", op, quantifier, criteriaImpl); + + return string.Format("{0} ({1}) {2}", op, criteriaImpl, quantifier); + } + + public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery) + { + return parameters.NamedParameters.Values.ToArray(); + } + + public override IProjection[] GetProjections() + { + return null; + } + + public void InitializeInnerQueryAndParameters(ICriteriaQuery criteriaQuery, bool forceReinitialization = false) + { + if (innerQuery == null || forceReinitialization) + { + ISessionFactoryImplementor factory = criteriaQuery.Factory; + + innerQuery = new CriteriaQueryTranslator( + factory, + criteriaImpl, //implicit polymorphism not supported (would need a union) + criteriaImpl.EntityOrClassName, + criteriaQuery.GenerateSQLAlias(), + criteriaQuery); + + types = innerQuery.HasProjection ? innerQuery.ProjectedTypes : null; + } + } + + public ICriteria Criteria + { + // NH-1146 + get { return criteriaImpl; } + } + } } \ No newline at end of file From 8c9686b75c22dc343c613658eff23a77cfe8039d Mon Sep 17 00:00:00 2001 From: ITMAGINATION Date: Tue, 21 Oct 2014 09:58:06 +0200 Subject: [PATCH 3/5] NH3727 bugfix proposition - missing csproj update --- src/NHibernate.Test/NHibernate.Test.csproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/NHibernate.Test/NHibernate.Test.csproj b/src/NHibernate.Test/NHibernate.Test.csproj index 962022b5487..ac2d03cac8c 100644 --- a/src/NHibernate.Test/NHibernate.Test.csproj +++ b/src/NHibernate.Test/NHibernate.Test.csproj @@ -797,6 +797,8 @@ + + From 76832ca14a4997054bf7683ce7100c82a6958b3f Mon Sep 17 00:00:00 2001 From: ITMAGINATION Date: Tue, 21 Oct 2014 11:15:10 +0200 Subject: [PATCH 4/5] Formatting fix: indentations by tabs instead of spaces. --- .../Criterion/SubqueryExpression.cs | 260 +++++++++--------- 1 file changed, 130 insertions(+), 130 deletions(-) diff --git a/src/NHibernate/Criterion/SubqueryExpression.cs b/src/NHibernate/Criterion/SubqueryExpression.cs index 924a2ac7c11..bbd7c977afe 100644 --- a/src/NHibernate/Criterion/SubqueryExpression.cs +++ b/src/NHibernate/Criterion/SubqueryExpression.cs @@ -10,134 +10,134 @@ namespace NHibernate.Criterion { - [Serializable] - public abstract class SubqueryExpression : AbstractCriterion - { - private readonly CriteriaImpl criteriaImpl; - private readonly String quantifier; - private readonly bool prefixOp; - private readonly String op; - private QueryParameters parameters; - private IType[] types; - - [NonSerialized] private CriteriaQueryTranslator innerQuery; - - protected SubqueryExpression(String op, String quantifier, DetachedCriteria dc) - : this(op, quantifier, dc, true) - { - } - - protected SubqueryExpression(String op, String quantifier, DetachedCriteria dc, bool prefixOp) - { - criteriaImpl = dc.GetCriteriaImpl(); - this.quantifier = quantifier; - this.prefixOp = prefixOp; - this.op = op; - } - - public IType[] GetTypes() - { - return types; - } - - protected abstract SqlString ToLeftSqlString(ICriteria criteria, ICriteriaQuery outerQuery); - - public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary enabledFilters) - { - InitializeInnerQueryAndParameters(criteriaQuery, true); // Force reinitialization. There can be old instance from earlier Criteria execution or cloned Criteria. - - if (innerQuery.HasProjection == false) - { - throw new QueryException("Cannot use subqueries on a criteria without a projection."); - } - - ISessionFactoryImplementor factory = criteriaQuery.Factory; - - IOuterJoinLoadable persister = (IOuterJoinLoadable)factory.GetEntityPersister(criteriaImpl.EntityOrClassName); - - //patch to generate joins on subqueries - //stolen from CriteriaLoader - CriteriaJoinWalker walker = - new CriteriaJoinWalker(persister, innerQuery, factory, criteriaImpl, criteriaImpl.EntityOrClassName, enabledFilters); - - parameters = innerQuery.GetQueryParameters(); // parameters can be inferred only after initialize the walker - - SqlString sql = walker.SqlString; - - if (criteriaImpl.FirstResult != 0 || criteriaImpl.MaxResults != RowSelection.NoValue) - { - int? offset = Loader.Loader.GetOffsetUsingDialect(parameters.RowSelection, factory.Dialect); - int? limit = Loader.Loader.GetLimitUsingDialect(parameters.RowSelection, factory.Dialect); - Parameter offsetParameter = offset.HasValue ? innerQuery.CreateSkipParameter(offset.Value) : null; - Parameter limitParameter = limit.HasValue ? innerQuery.CreateTakeParameter(limit.Value) : null; - sql = factory.Dialect.GetLimitString(sql, offset, limit, offsetParameter, limitParameter); - } - - // during CriteriaImpl.Clone we are doing a shallow copy of each criterion. - // this is not a problem for common criterion but not for SubqueryExpression because here we are holding the state of inner CriteriaTraslator (ICriteriaQuery). - // After execution (ToSqlString) we have to clean the internal state because the next execution may be performed in a different tree reusing the same istance of SubqueryExpression. - innerQuery = null; - - SqlStringBuilder buf = new SqlStringBuilder().Add(ToLeftSqlString(criteria, criteriaQuery)); - if (op != null) - { - buf.Add(" ").Add(op).Add(" "); - } - - if (quantifier != null && prefixOp) - { - buf.Add(quantifier).Add(" "); - } - - buf.Add("(").Add(sql).Add(")"); - - if (quantifier != null && prefixOp == false) - { - buf.Add(" ").Add(quantifier); - } - - return buf.ToSqlString(); - } - - public override string ToString() - { - if (prefixOp) - return string.Format("{0} {1} ({2})", op, quantifier, criteriaImpl); - - return string.Format("{0} ({1}) {2}", op, criteriaImpl, quantifier); - } - - public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery) - { - return parameters.NamedParameters.Values.ToArray(); - } - - public override IProjection[] GetProjections() - { - return null; - } - - public void InitializeInnerQueryAndParameters(ICriteriaQuery criteriaQuery, bool forceReinitialization = false) - { - if (innerQuery == null || forceReinitialization) - { - ISessionFactoryImplementor factory = criteriaQuery.Factory; - - innerQuery = new CriteriaQueryTranslator( - factory, - criteriaImpl, //implicit polymorphism not supported (would need a union) - criteriaImpl.EntityOrClassName, - criteriaQuery.GenerateSQLAlias(), - criteriaQuery); - - types = innerQuery.HasProjection ? innerQuery.ProjectedTypes : null; - } - } - - public ICriteria Criteria - { - // NH-1146 - get { return criteriaImpl; } - } - } + [Serializable] + public abstract class SubqueryExpression : AbstractCriterion + { + private readonly CriteriaImpl criteriaImpl; + private readonly String quantifier; + private readonly bool prefixOp; + private readonly String op; + private QueryParameters parameters; + private IType[] types; + + [NonSerialized] private CriteriaQueryTranslator innerQuery; + + protected SubqueryExpression(String op, String quantifier, DetachedCriteria dc) + : this(op, quantifier, dc, true) + { + } + + protected SubqueryExpression(String op, String quantifier, DetachedCriteria dc, bool prefixOp) + { + criteriaImpl = dc.GetCriteriaImpl(); + this.quantifier = quantifier; + this.prefixOp = prefixOp; + this.op = op; + } + + public IType[] GetTypes() + { + return types; + } + + protected abstract SqlString ToLeftSqlString(ICriteria criteria, ICriteriaQuery outerQuery); + + public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary enabledFilters) + { + InitializeInnerQueryAndParameters(criteriaQuery, true); // Force reinitialization. There can be old instance from earlier Criteria execution or cloned Criteria. + + if (innerQuery.HasProjection == false) + { + throw new QueryException("Cannot use subqueries on a criteria without a projection."); + } + + ISessionFactoryImplementor factory = criteriaQuery.Factory; + + IOuterJoinLoadable persister = (IOuterJoinLoadable)factory.GetEntityPersister(criteriaImpl.EntityOrClassName); + + //patch to generate joins on subqueries + //stolen from CriteriaLoader + CriteriaJoinWalker walker = + new CriteriaJoinWalker(persister, innerQuery, factory, criteriaImpl, criteriaImpl.EntityOrClassName, enabledFilters); + + parameters = innerQuery.GetQueryParameters(); // parameters can be inferred only after initialize the walker + + SqlString sql = walker.SqlString; + + if (criteriaImpl.FirstResult != 0 || criteriaImpl.MaxResults != RowSelection.NoValue) + { + int? offset = Loader.Loader.GetOffsetUsingDialect(parameters.RowSelection, factory.Dialect); + int? limit = Loader.Loader.GetLimitUsingDialect(parameters.RowSelection, factory.Dialect); + Parameter offsetParameter = offset.HasValue ? innerQuery.CreateSkipParameter(offset.Value) : null; + Parameter limitParameter = limit.HasValue ? innerQuery.CreateTakeParameter(limit.Value) : null; + sql = factory.Dialect.GetLimitString(sql, offset, limit, offsetParameter, limitParameter); + } + + // during CriteriaImpl.Clone we are doing a shallow copy of each criterion. + // this is not a problem for common criterion but not for SubqueryExpression because here we are holding the state of inner CriteriaTraslator (ICriteriaQuery). + // After execution (ToSqlString) we have to clean the internal state because the next execution may be performed in a different tree reusing the same istance of SubqueryExpression. + innerQuery = null; + + SqlStringBuilder buf = new SqlStringBuilder().Add(ToLeftSqlString(criteria, criteriaQuery)); + if (op != null) + { + buf.Add(" ").Add(op).Add(" "); + } + + if (quantifier != null && prefixOp) + { + buf.Add(quantifier).Add(" "); + } + + buf.Add("(").Add(sql).Add(")"); + + if (quantifier != null && prefixOp == false) + { + buf.Add(" ").Add(quantifier); + } + + return buf.ToSqlString(); + } + + public override string ToString() + { + if (prefixOp) + return string.Format("{0} {1} ({2})", op, quantifier, criteriaImpl); + + return string.Format("{0} ({1}) {2}", op, criteriaImpl, quantifier); + } + + public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery) + { + return parameters.NamedParameters.Values.ToArray(); + } + + public override IProjection[] GetProjections() + { + return null; + } + + public void InitializeInnerQueryAndParameters(ICriteriaQuery criteriaQuery, bool forceReinitialization = false) + { + if (innerQuery == null || forceReinitialization) + { + ISessionFactoryImplementor factory = criteriaQuery.Factory; + + innerQuery = new CriteriaQueryTranslator( + factory, + criteriaImpl, //implicit polymorphism not supported (would need a union) + criteriaImpl.EntityOrClassName, + criteriaQuery.GenerateSQLAlias(), + criteriaQuery); + + types = innerQuery.HasProjection ? innerQuery.ProjectedTypes : null; + } + } + + public ICriteria Criteria + { + // NH-1146 + get { return criteriaImpl; } + } + } } \ No newline at end of file From 84adfa45f86a7227c071007a04f36f6b255a925c Mon Sep 17 00:00:00 2001 From: ITMAGINATION Date: Tue, 21 Oct 2014 12:06:28 +0200 Subject: [PATCH 5/5] Formatting fix (FixtureByCode.cs): indentations by tabs instead of spaces. --- .../NHSpecificTest/NH3727/FixtureByCode.cs | 136 +++++++++--------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/src/NHibernate.Test/NHSpecificTest/NH3727/FixtureByCode.cs b/src/NHibernate.Test/NHSpecificTest/NH3727/FixtureByCode.cs index 8cd42d9c1b5..77598d80853 100644 --- a/src/NHibernate.Test/NHSpecificTest/NH3727/FixtureByCode.cs +++ b/src/NHibernate.Test/NHSpecificTest/NH3727/FixtureByCode.cs @@ -9,85 +9,85 @@ namespace NHibernate.Test.NHSpecificTest.NH3727 { - public class ByCodeFixture : TestCaseMappingByCode - { - protected override HbmMapping GetMappings() - { - var mapper = new ModelMapper(); - mapper.Class(rc => - { - rc.Id(x => x.Id); - }); + public class ByCodeFixture : TestCaseMappingByCode + { + protected override HbmMapping GetMappings() + { + var mapper = new ModelMapper(); + mapper.Class(rc => + { + rc.Id(x => x.Id); + }); - return mapper.CompileMappingForAllExplicitlyAddedEntities(); - } + return mapper.CompileMappingForAllExplicitlyAddedEntities(); + } - [Test] - public void QueryOverWithSubqueryProjectionCanBeExecutedMoreThanOnce() - { - using (ISession session = OpenSession()) - using (session.BeginTransaction()) - { - const int parameter1 = 111; + [Test] + public void QueryOverWithSubqueryProjectionCanBeExecutedMoreThanOnce() + { + using (ISession session = OpenSession()) + using (session.BeginTransaction()) + { + const int parameter1 = 111; - var countSubquery = QueryOver.Of() - .Where(x => x.Id == parameter1) //any condition which makes output SQL has parameter - .Select(Projections.RowCount()) - ; + var countSubquery = QueryOver.Of() + .Where(x => x.Id == parameter1) //any condition which makes output SQL has parameter + .Select(Projections.RowCount()) + ; - var originalQueryOver = session.QueryOver() - .SelectList(l => l - .Select(x => x.Id) - .SelectSubQuery(countSubquery) - ) - .TransformUsing(Transformers.ToList); + var originalQueryOver = session.QueryOver() + .SelectList(l => l + .Select(x => x.Id) + .SelectSubQuery(countSubquery) + ) + .TransformUsing(Transformers.ToList); - originalQueryOver.List(); + originalQueryOver.List(); - Assert.DoesNotThrow(() => originalQueryOver.List(), "Second try to execute QueryOver thrown exception."); - } - } + Assert.DoesNotThrow(() => originalQueryOver.List(), "Second try to execute QueryOver thrown exception."); + } + } - [Test] - public void ClonedQueryOverExecutionMakesOriginalQueryOverNotWorking() - { - // Projections are copied by clone operation. - // SubqueryProjection use SubqueryExpression which holds CriteriaQueryTranslator (class SubqueryExpression { private CriteriaQueryTranslator innerQuery; }) - // So given CriteriaQueryTranslator is used twice. - // Since CriteriaQueryTranslator has CollectedParameters collection, second execution of the Criteria does not fit SqlCommand parameters. + [Test] + public void ClonedQueryOverExecutionMakesOriginalQueryOverNotWorking() + { + // Projections are copied by clone operation. + // SubqueryProjection use SubqueryExpression which holds CriteriaQueryTranslator (class SubqueryExpression { private CriteriaQueryTranslator innerQuery; }) + // So given CriteriaQueryTranslator is used twice. + // Since CriteriaQueryTranslator has CollectedParameters collection, second execution of the Criteria does not fit SqlCommand parameters. - using (ISession session = OpenSession()) - using (session.BeginTransaction()) - { - const int parameter1 = 111; + using (ISession session = OpenSession()) + using (session.BeginTransaction()) + { + const int parameter1 = 111; - var countSubquery = QueryOver.Of() - .Where(x => x.Id == parameter1) //any condition which makes output SQL has parameter - .Select(Projections.RowCount()) - ; + var countSubquery = QueryOver.Of() + .Where(x => x.Id == parameter1) //any condition which makes output SQL has parameter + .Select(Projections.RowCount()) + ; - var originalQueryOver = session.QueryOver() - //.Where(x => x.Id == parameter2) - .SelectList(l => l - .Select(x => x.Id) - .SelectSubQuery(countSubquery) - ) - .TransformUsing(Transformers.ToList); + var originalQueryOver = session.QueryOver() + //.Where(x => x.Id == parameter2) + .SelectList(l => l + .Select(x => x.Id) + .SelectSubQuery(countSubquery) + ) + .TransformUsing(Transformers.ToList); - var clonedQueryOver = originalQueryOver.Clone(); - clonedQueryOver.List(); + var clonedQueryOver = originalQueryOver.Clone(); + clonedQueryOver.List(); - Assert.DoesNotThrow(() => originalQueryOver.List(), "Cloned QueryOver execution caused source QueryOver throw exception when executed."); - } - } + Assert.DoesNotThrow(() => originalQueryOver.List(), "Cloned QueryOver execution caused source QueryOver throw exception when executed."); + } + } - private static IEnumerable GetProjectionList(IQueryOver clonedQueryOver) - { - var projectionList = (((CriteriaImpl)clonedQueryOver.RootCriteria).Projection as ProjectionList); - for (int i = 0; i < projectionList.Length; i++) - { - yield return projectionList[i]; - } - } - } + private static IEnumerable GetProjectionList(IQueryOver clonedQueryOver) + { + var projectionList = (((CriteriaImpl)clonedQueryOver.RootCriteria).Projection as ProjectionList); + for (int i = 0; i < projectionList.Length; i++) + { + yield return projectionList[i]; + } + } + } } \ No newline at end of file