This issue is likely related to NH1760 (https://nhibernate.jira.com/browse/NH-1760). In fact, my testcase is just the code included in the comments of NH1760, reformulated into an NHSpecificTest
Richard Birkby
May 30, 2012 at 11:02 AM
The testcase in the pull request generates the following exception:
NHibernate.Test.NHSpecificTest.NH3171.Fixture.SqlShouldIncludeAliasAsJoinWhenRestrictingByCompositeKeyColumn: NHibernate.Exceptions.GenericADOException : could not execute query [ SELECT this_.Song as Song0_0_, this_.Country as Country0_0_, this_.Name as Name0_0_ FROM Artist this_ WHERE s1_.Name = @p0 ] Name:cp0 - Value:Miss Kiss Kiss Bang [SQL: SELECT this_.Song as Song0_0_, this_.Country as Country0_0_, this_.Name as Name0_0_ FROM Artist this_ WHERE s1_.Name = @p0] ----> System.Data.SqlClient.SqlException : The multi-part identifier "s1_.Name" could not be bound.
With a simple Criteria query such as:
s.CreateCriteria<Artist>("a")
.CreateAlias("a.Song", "s")
.Add(Restrictions.Eq("s.Name", "Miss Kiss Kiss Bang"))
NHibernate fails to include the join to Song in the SQL query when Song is a composite column.
GitHub pull request with testcase will be included in the comments.