-
Notifications
You must be signed in to change notification settings - Fork 936
NH-3609 - Fix using Projections.Conditional inside of Projections.Count #261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH3609 | ||
{ | ||
class Entity | ||
{ | ||
public virtual Guid Id { get; set; } | ||
public virtual string Name { get; set; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System.Linq; | ||
using NHibernate.Criterion; | ||
using NHibernate.Linq; | ||
using NHibernate.Transform; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH3609 | ||
{ | ||
[TestFixture] | ||
public class Fixture : BugTestCase | ||
{ | ||
protected override void OnSetUp() | ||
{ | ||
using (ISession session = OpenSession()) | ||
using (ITransaction transaction = session.BeginTransaction()) | ||
{ | ||
var e1 = new Entity {Name = "Bob"}; | ||
session.Save(e1); | ||
|
||
var e2 = new Entity {Name = "Sally"}; | ||
session.Save(e2); | ||
|
||
session.Flush(); | ||
transaction.Commit(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (ISession session = OpenSession()) | ||
using (ITransaction transaction = session.BeginTransaction()) | ||
{ | ||
session.Delete("from System.Object"); | ||
|
||
session.Flush(); | ||
transaction.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void CountWithConditionalDoesNotThrow() | ||
{ | ||
using (ISession session = OpenSession()) | ||
using (session.BeginTransaction()) | ||
{ | ||
MappingEntity mappingEntity = null; | ||
Assert.DoesNotThrow(() => | ||
session.QueryOver<Entity>().SelectList( | ||
builder => | ||
builder.Select(Projections.Count(Projections.Conditional( | ||
Restrictions.Eq(Projections.Property<Entity>(x => x.Name), "FOO"), | ||
Projections.Constant("", NHibernateUtil.String), | ||
Projections.Constant(null, NHibernateUtil.String))).WithAlias(() => mappingEntity.Count)) | ||
) | ||
.TransformUsing(Transformers.AliasToBean<MappingEntity>()).List<MappingEntity>() | ||
); | ||
} | ||
} | ||
|
||
[Test] | ||
public void GroupByClauseHasParameterSet() | ||
{ | ||
using (ISession session = OpenSession()) | ||
using (session.BeginTransaction()) | ||
{ | ||
MappingEntity mappingEntity = null; | ||
Assert.DoesNotThrow(() => | ||
session.QueryOver<Entity>().SelectList( | ||
builder => | ||
builder.Select(Projections.GroupProperty( | ||
Projections.Conditional( | ||
Restrictions.Eq(Projections.Property<Entity>(x => x.Name), ""), | ||
Projections.Constant(1), Projections.Constant(2))) | ||
.WithAlias(() => mappingEntity.Count)) | ||
) | ||
.TransformUsing(Transformers.AliasToBean<MappingEntity>()).List<MappingEntity>() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you check something here? |
||
); | ||
} | ||
|
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH3609 | ||
{ | ||
class MappingEntity | ||
{ | ||
public virtual int Count { get; set; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" namespace="NHibernate.Test.NHSpecificTest.NH3609"> | ||
|
||
<class name="Entity"> | ||
<id name="Id" generator="guid.comb" /> | ||
<property name="Name" /> | ||
</class> | ||
|
||
</hibernate-mapping> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,12 +20,14 @@ public GroupedProjection(IProjection projection) | |
|
||
public virtual SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) | ||
{ | ||
return projection.ToSqlString(criteria, position, criteriaQuery, enabledFilters); | ||
var thinger = projection.ToSqlString(criteria, position, criteriaQuery, enabledFilters); | ||
return thinger; | ||
} | ||
|
||
public virtual SqlString ToGroupSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) | ||
{ | ||
return SqlStringHelper.RemoveAsAliasesFromSql(this.projection.ToSqlString(criteria, 0, criteriaQuery, enabledFilters)); | ||
var thinger = SqlStringHelper.RemoveAsAliasesFromSql(this.projection.ToSqlString(criteria, 0, criteriaQuery, enabledFilters)); | ||
return thinger; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please revert changes to this file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure thing, I'm kinda new to git, is there a way for me to edit the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could use GitHub for Windows. 2014-04-03 0:45 GMT+02:00 braahyan [email protected]:
|
||
|
||
public virtual IType[] GetTypes(ICriteria criteria, ICriteriaQuery criteriaQuery) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check something here?