Is there any way to execute following query with native NHibernate linq provider?
var result =
(from e1 in Session.Query()
join e2 in Se
I'm not quite sure when this was introduced but this is now supported by NHibernate. I am using version 3.3.1 and I have a query very similar to yours working well. The test below works for me:
[TestFixture]
public class NHibernateJoinUnrelatedEntitiesTest
{
private ISessionFactory sessionFactory;
[Test]
public void I_Can_Join_Unrelated_Entities()
{
// Arrange
ISession session = sessionFactory.OpenSession();
// Act
var results = (
from c in session.Query()
from wal in session.Query()
where c.Id == wal.CustomerId
&& c.Id == 54856
select new { CustomerId = c.Id, Name = c.FirstName, Address = wal.IpAddress }
).ToList();
// Assert
Assert.NotNull( results );
}
public class Customer
{
public virtual int Id { get; set; }
public virtual string FirstName { get; set; }
}
public class WebsiteActivityLog
{
public virtual int Id { get; set; }
public virtual int CustomerId { get; set; }
public virtual string IpAddress { get; set; }
}
public class CustomerMap : ClassMap
{
public CustomerMap()
{
Id( x => x.Id );
Map( x => x.FirstName );
}
}
public class WebsiteActivityLogMap : ClassMap
{
public WebsiteActivityLogMap()
{
Id( x => x.Id );
Map( x => x.CustomerId );
Map( x => x.IpAddress );
}
}
}