-
Notifications
You must be signed in to change notification settings - Fork 934
Apply filters for entity joins in hql #2550
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f257331
Apply filters for entity joins
bahusoid adba14a
Added test for QueryOver
bahusoid c6d9b29
Delete EntityJoinJoinSequenceImpl
hazzik d5408fd
Delete obsolete comment
hazzik bc28e1f
Add comment about EntityJoinJoinSequenceImpl
bahusoid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
src/NHibernate.Test/Async/NHSpecificTest/GH2549/Fixture.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by AsyncGenerator. | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
|
||
using System.Linq; | ||
using NUnit.Framework; | ||
using NHibernate.Linq; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH2549 | ||
{ | ||
using System.Threading.Tasks; | ||
[TestFixture] | ||
public class FixtureAsync : BugTestCase | ||
{ | ||
protected override void OnSetUp() | ||
{ | ||
using (var s = OpenSession()) | ||
using (var t = s.BeginTransaction()) | ||
{ | ||
s.Save(new Person {Id = 1, Name = "Name"}); | ||
s.Save(new Customer {Deleted = false, Name = "Name", Id = 1}); | ||
s.Save(new Customer {Deleted = true, Name = "Name", Id = 2}); | ||
|
||
t.Commit(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var s = OpenSession()) | ||
using (var t = s.BeginTransaction()) | ||
{ | ||
s.CreateQuery("delete from System.Object").ExecuteUpdate(); | ||
t.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task EntityJoinFilterLinqAsync() | ||
{ | ||
using (var s = OpenSession()) | ||
{ | ||
var list = await ((from p in s.Query<Person>() | ||
join c in s.Query<Customer>() on p.Name equals c.Name | ||
select p).ToListAsync()); | ||
|
||
s.EnableFilter("DeletedCustomer").SetParameter("deleted", false); | ||
|
||
var filteredList = await ((from p in s.Query<Person>() | ||
join c in s.Query<Customer>() on p.Name equals c.Name | ||
select p).ToListAsync()); | ||
|
||
Assert.That(list, Has.Count.EqualTo(2)); | ||
Assert.That(filteredList, Has.Count.EqualTo(1)); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task EntityJoinFilterQueryOverAsync() | ||
{ | ||
using (var s = OpenSession()) | ||
{ | ||
Customer c = null; | ||
Person p = null; | ||
var list = await (s.QueryOver(() => p).JoinEntityAlias(() => c, () => c.Name == p.Name).ListAsync()); | ||
|
||
s.EnableFilter("DeletedCustomer").SetParameter("deleted", false); | ||
|
||
var filteredList = await (s.QueryOver(() => p).JoinEntityAlias(() => c, () => c.Name == p.Name).ListAsync()); | ||
|
||
Assert.That(list, Has.Count.EqualTo(2)); | ||
Assert.That(filteredList, Has.Count.EqualTo(1)); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System.Linq; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH2549 | ||
{ | ||
[TestFixture] | ||
public class Fixture : BugTestCase | ||
{ | ||
protected override void OnSetUp() | ||
{ | ||
using (var s = OpenSession()) | ||
using (var t = s.BeginTransaction()) | ||
{ | ||
s.Save(new Person {Id = 1, Name = "Name"}); | ||
s.Save(new Customer {Deleted = false, Name = "Name", Id = 1}); | ||
s.Save(new Customer {Deleted = true, Name = "Name", Id = 2}); | ||
|
||
t.Commit(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var s = OpenSession()) | ||
using (var t = s.BeginTransaction()) | ||
{ | ||
s.CreateQuery("delete from System.Object").ExecuteUpdate(); | ||
t.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void EntityJoinFilterLinq() | ||
{ | ||
using (var s = OpenSession()) | ||
{ | ||
var list = (from p in s.Query<Person>() | ||
join c in s.Query<Customer>() on p.Name equals c.Name | ||
select p).ToList(); | ||
|
||
s.EnableFilter("DeletedCustomer").SetParameter("deleted", false); | ||
|
||
var filteredList = (from p in s.Query<Person>() | ||
join c in s.Query<Customer>() on p.Name equals c.Name | ||
select p).ToList(); | ||
|
||
Assert.That(list, Has.Count.EqualTo(2)); | ||
Assert.That(filteredList, Has.Count.EqualTo(1)); | ||
} | ||
} | ||
|
||
[Test] | ||
public void EntityJoinFilterQueryOver() | ||
{ | ||
using (var s = OpenSession()) | ||
{ | ||
Customer c = null; | ||
Person p = null; | ||
var list = s.QueryOver(() => p).JoinEntityAlias(() => c, () => c.Name == p.Name).List(); | ||
|
||
s.EnableFilter("DeletedCustomer").SetParameter("deleted", false); | ||
|
||
var filteredList = s.QueryOver(() => p).JoinEntityAlias(() => c, () => c.Name == p.Name).List(); | ||
|
||
Assert.That(list, Has.Count.EqualTo(2)); | ||
Assert.That(filteredList, Has.Count.EqualTo(1)); | ||
} | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/NHibernate.Test/NHSpecificTest/GH2549/Mappings.hbm.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" | ||
namespace="NHibernate.Test.NHSpecificTest.GH2549" > | ||
|
||
<class name="Customer"> | ||
<id name="Id"> | ||
<generator class="assigned" /> | ||
</id> | ||
<property name="Name" /> | ||
<property name="Deleted" type="Boolean" not-null="true" /> | ||
|
||
<filter name="DeletedCustomer" condition="Deleted = :deleted" /> | ||
</class> | ||
|
||
<class name="Person"> | ||
<id name="Id"> | ||
<generator class="assigned" /> | ||
</id> | ||
<property name="Name" /> | ||
</class> | ||
|
||
<filter-def name="DeletedCustomer"> | ||
<filter-param name="deleted" type="Boolean"/> | ||
</filter-def> | ||
|
||
</hibernate-mapping> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace NHibernate.Test.NHSpecificTest.GH2549 | ||
{ | ||
public class Customer | ||
{ | ||
public virtual int Id { get; set; } | ||
public virtual bool Deleted { get; set; } | ||
public virtual string Name { get; set; } | ||
} | ||
|
||
public class Person | ||
{ | ||
public virtual int Id { get; set; } | ||
public virtual string Name { get; set; } | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.