Sorry about short first post - I thought somebody struggled with it and didn;t want to waste place here.
But, ok:
NHibernate 2.0GA
MS SQL Server 2005 with correspondent dialect.
Below is the test package that fully describes the problenm and how to reproduce it.
To run test:
1. Move these files to folder created in directory …\NHibernate\src\NHibernate.Test\ and include it into the project
2. Create NHTEST database, specify connection string in …\NHibernate\src\NHibernate.Test\hibernate.cfg.xml
3. Run.
Hope this will help
Mapping file (Mappings.hbm.xml):
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="NHibernate.Test">
<class name="NHibernate.Test.Eproc2Test.User" table="Principal">
<!-- Id -->
<id name="Id" type="Guid" column="Id" unsaved-value="00000000-0000-0000-0000-000000000000">
<generator class="guid.comb" />
</id>
<property name="Name" column="Name" not-null="true" />
<many-to-one fetch="join" name="Organisation" class="NHibernate.Test.Eproc2Test.Organisation" column="OrganisationId"/>
</class>
<class name="NHibernate.Test.Eproc2Test.Organisation" table="Organisation">
<!-- Id -->
<id name="Id" type="Guid" column="Id" unsaved-value="00000000-0000-0000-0000-000000000000">
<generator class="guid.comb" />
</id>
<property name="Name" column="Name" not-null="true" />
</class>
</hibernate-mapping>
Organisation.cs
Code:
using System;
namespace NHibernate.Test.Eproc2Test
{
public class Organisation
{
public virtual Guid Id { get; set; }
public virtual string Name { get; set; }
}
}
User.cs
Code:
using System;
namespace NHibernate.Test.Eproc2Test
{
public class User
{
public const string REL_ORGANISATION = "Organisation";
public virtual Guid Id { get; set; }
public virtual string Name { get; set; }
public virtual Organisation Organisation { get; set; }
}
}
Fixture.cs
Code:
using System.Collections;
using NHibernate.Criterion;
using NHibernate.SqlCommand;
using NUnit.Framework;
namespace NHibernate.Test.Eproc2Test
{
[TestFixture]
public class AmbigiousFieldTest : TestCase
{
private const string ORG_ALIAS = "OrganisationAlias";
private const string ORG_NAME_ALIAS = "OrganisationName";
private const string PROP_NAME = "Name";
[Test]
public void SortByAmbigiousField()
{
var criteria = cfg.BuildSessionFactory().OpenSession().CreateCriteria(typeof(User));
criteria.CreateCriteria(User.REL_ORGANISATION, ORG_ALIAS, JoinType.InnerJoin);
criteria.SetProjection(Projections.Property(PROP_NAME));
criteria.SetProjection(Projections.Alias(Projections.Property(ORG_ALIAS+"."+PROP_NAME), ORG_NAME_ALIAS));
criteria.AddOrder(Order.Asc(ORG_NAME_ALIAS));
// bug appeared when paging enabled
criteria.SetFirstResult(0);
criteria.SetMaxResults(15);
// exception is thrown
criteria.List();
}
/// <summary>
/// Mapping files used in the TestCase
/// </summary>
protected override IList Mappings
{
get { return new[] { "Eproc2Test.Mappings.hbm.xml" }; }
}
/// <summary>
/// Assembly to load mapping files from (default is NHibernate.DomainModel).
/// </summary>
protected override string MappingsAssembly
{
get { return "NHibernate.Test"; }
}
}
}