Skip to content
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

Add support for joining a subquery in hql #2551

Merged
merged 21 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/NHibernate.DomainModel/Northwind/Entities/CompositeOrder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;

namespace NHibernate.DomainModel.Northwind.Entities
{
public class CompositeOrder : IEquatable<CompositeOrder>
{
public virtual int OrderId { get; set; }

public virtual Customer Customer { get; set; }

public virtual DateTime? OrderDate { get; set; }

public virtual DateTime? RequiredDate { get; set; }

public virtual DateTime? ShippingDate { get; set; }

public virtual Shipper Shipper { get; set; }

public virtual decimal? Freight { get; set; }

public virtual string ShippedTo { get; set; }

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != GetType()) return false;
return Equals((CompositeOrder) obj);
}

public virtual bool Equals(CompositeOrder other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return OrderId == other.OrderId && Equals(Customer, other.Customer);
}

public override int GetHashCode()
{
unchecked
{
return (OrderId * 397) ^ (Customer != null ? Customer.GetHashCode() : 0);
}
}
}
}
7 changes: 6 additions & 1 deletion src/NHibernate.DomainModel/Northwind/Entities/Northwind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ public IQueryable<Order> Orders
{
get { return _session.Query<Order>(); }
}


public IQueryable<CompositeOrder> CompositeOrders
{
get { return _session.Query<CompositeOrder>(); }
}

public IQueryable<OrderLine> OrderLines
{
get { return _session.Query<OrderLine>(); }
Expand Down
2 changes: 2 additions & 0 deletions src/NHibernate.DomainModel/Northwind/Entities/Order.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public virtual ISet<OrderLine> OrderLines
get { return _orderLines; }
}

public virtual ISet<int> ProductIds { get; set; }

public virtual void AddOrderLine(OrderLine orderLine)
{
if (!_orderLines.Contains(orderLine))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernate.DomainModel.Northwind.Entities" assembly="NHibernate.DomainModel">
<class name="CompositeOrder" mutable="false" schema-action="none">
<subselect>
select * from Orders
</subselect>

<composite-id unsaved-value="any">
<key-property name="OrderId" column="OrderId" />
<key-many-to-one name="Customer" column="CustomerId" />
</composite-id>

<property name="OrderDate" column="OrderDate" />
<property name="RequiredDate" column="RequiredDate" />
<property name="ShippingDate" column="ShippedDate" />
<many-to-one name="Shipper" column="ShipVia" fetch="select"/>
<property name="Freight" column="Freight" />
<property name="ShippedTo" column="ShipName" type="string" length="40" />

</class>
</hibernate-mapping>
5 changes: 5 additions & 0 deletions src/NHibernate.DomainModel/Northwind/Mappings/Order.hbm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
<key column="OrderId"/>
<one-to-many class="OrderLine"/>
</set>

<set name="ProductIds" table="OrderLines">
<key column="OrderId" />
<element column="ProductId" type="Int32" />
</set>

</class>

Expand Down
Loading