score:0
It's still not supported.
You should either introduce a relation between the objects or use SQL for the query.
score:1
Not using LINQ, but you can do theta joins when using HQL.
Select e1.Id, e1.SomeField, e2.SomeUnrelatedField
from Entity1 e1, Entity2 e2 where e1.SomeField = e2.SomeField
However, you won't be able to do outer joins with this. So if that's a requirement, you'll have to go with raw SQL.
score:2
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<Customer>()
from wal in session.Query<WebsiteActivityLog>()
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<Customer>
{
public CustomerMap()
{
Id( x => x.Id );
Map( x => x.FirstName );
}
}
public class WebsiteActivityLogMap : ClassMap<WebsiteActivityLog>
{
public WebsiteActivityLogMap()
{
Id( x => x.Id );
Map( x => x.CustomerId );
Map( x => x.IpAddress );
}
}
}
Source: stackoverflow.com
Related Articles
- nhibernate queryover with complex join over non-related entities
- NHibernate. Join unrelated entities
- How to join columns or properties of entities that belongs as many relationship to another entity in .NET EF Code First
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- nHibernate 3 - Left Join re-Linq solution
- Antlr exception with message "plan b" when walking IQueryable of NHibernate entities
- NHibernate 3.x deletes child entities when combining LINQ paging, many-to-many, and subselect fetch
- LINQ to Entities Join on Nullable Field where Null Implies "Match All"
- Left outer join using LINQ -- understanding the code
- LINQ to Entities Join on DateTime.DayOfWeek
- Outer join query using LINQ to Entities
- NHibernate 3 LINQ inner join issue with three jumps: NotSupportedException
- LINQ Source Code Available
- Linq to entities Left Join
- LINQ to Entities three table join query
- Linq join() - Join two entities and select one
- Refactor Linq code and "LINQ to Entities does not recognize the method"
- .NET 4 Code Contracts: "requires unproven: source != null"
- EF Linq to Entities calling ToList() on entity set generates SQL command containing multiple left outer join
- How can I code an outer join using LINQ and EF6?
- Left join in linq in NHibernate 3.2
- LINQ join query with relational entities
- Linq 2 Entities : Performing a join on two columns with different types
- Linq to Entities Left outer join grouped into a collection
- Query expressions over source type 'dynamic' or with a join sequence of type 'dynamic' are not allowed
- Only parameterless constructors and initializers are supported in LINQ to Entities in linq join with tuples
- How linq to nhibernate by join and Separate where in query
- Left Outer Join in Linq to Entities / SQL
- creating Linq to sqlite dbml from DbLinq source code
- LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance
- c# to read xml file and update the checkboxes with the nodes
- for loop in where clause
- How can I join datasets from multiple tables with only certain columns in EF Core?
- Get All record group by date and hour if any column have null value
- Linq query throws NullReferenceException when pulling data from SQLite, why?
- Linq To Sql Sub Query Complex
- cannot implicitly convert type in LINQ
- Shouldn't the 'range variable' from the join return a list with all members that are the same?
- Re-using LINQ query based on bool value
- C# LINQ use xml with case insensitive queries
- Using Results from LINQ Join within Repeater
- linq/ef: How to form the query which connects multiple tables to return result?
- Grouping data with datatable with ASP.NET
- EF Code First oddity with Distinct()
- LINQ version of SQL Group By
- Lambda expression where id in list of ids
- c# Linq, print name by value from array
- Using Linq, How can I properly append multiple Where clauses so that they appear in the appropriate order?
- How to return an IEnumerable of type X from a method
- Duplicates in results from .ToArray in LinQ query