-
Notifications
You must be signed in to change notification settings - Fork 936
NH-3845 - Make OfType work better with polymorphic mappings #456
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
Open
abrobston
wants to merge
4
commits into
nhibernate:master
Choose a base branch
from
abrobston:NH3845
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
13 changes: 13 additions & 0 deletions
13
src/NHibernate.Test/NHSpecificTest/NH3845/Concrete/MainEntity.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,13 @@ | ||
using System.Collections.Generic; | ||
using NHibernate.Test.NHSpecificTest.NH3845.Interfaces; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH3845.Concrete | ||
{ | ||
public class MainEntity : IMainEntity | ||
{ | ||
public virtual int MainEntityId { get; set; } | ||
public virtual string Text { get; set; } | ||
public virtual ISet<IPropertyEntityBase> Properties { get; protected set; } = new HashSet<IPropertyEntityBase>(); | ||
public virtual ISet<ISeparateEntity> SeparateEntities { get; protected set; } = new HashSet<ISeparateEntity>(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/NHibernate.Test/NHSpecificTest/NH3845/Concrete/PropertyEntityA.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,9 @@ | ||
using NHibernate.Test.NHSpecificTest.NH3845.Interfaces; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH3845.Concrete | ||
{ | ||
public class PropertyEntityA : PropertyEntityBase, IPropertyEntityA | ||
{ | ||
public virtual int SerialNumber { get; set; } | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/NHibernate.Test/NHSpecificTest/NH3845/Concrete/PropertyEntityB.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,10 @@ | ||
using NHibernate.Test.NHSpecificTest.NH3845.Interfaces; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH3845.Concrete | ||
{ | ||
public class PropertyEntityB : PropertyEntityBase, IPropertyEntityB | ||
{ | ||
public virtual string Description { get; set; } | ||
public virtual string AnotherString { get; set; } | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/NHibernate.Test/NHSpecificTest/NH3845/Concrete/PropertyEntityBase.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,12 @@ | ||
using NHibernate.Test.NHSpecificTest.NH3845.Interfaces; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH3845.Concrete | ||
{ | ||
public abstract class PropertyEntityBase : IPropertyEntityBase | ||
{ | ||
public virtual int PropertyEntityBaseId { get; set; } | ||
public virtual string Name { get; set; } | ||
public virtual string SharedValue { get; set; } | ||
public virtual IMainEntity MainEntity { get; set; } | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/NHibernate.Test/NHSpecificTest/NH3845/Concrete/PropertyEntityC.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,10 @@ | ||
using NHibernate.Test.NHSpecificTest.NH3845.Interfaces; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH3845.Concrete | ||
{ | ||
public class PropertyEntityC : PropertyEntityBase, IPropertyEntityC | ||
{ | ||
public virtual string Description { get; set; } | ||
public virtual int AnotherNumber { get; set; } | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/NHibernate.Test/NHSpecificTest/NH3845/Concrete/SeparateEntity.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,11 @@ | ||
using NHibernate.Test.NHSpecificTest.NH3845.Interfaces; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH3845.Concrete | ||
{ | ||
public class SeparateEntity : ISeparateEntity | ||
{ | ||
public virtual int SeparateEntityId { get; set; } | ||
public virtual IMainEntity MainEntity { get; set; } | ||
public virtual int SeparateEntityValue { 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
using System.Linq; | ||
using NHibernate.Linq; | ||
using NHibernate.Test.NHSpecificTest.NH3845.Concrete; | ||
using NHibernate.Test.NHSpecificTest.NH3845.Interfaces; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH3845 | ||
{ | ||
[TestFixture] | ||
public class Fixture : BugTestCase | ||
{ | ||
protected override void OnSetUp() | ||
{ | ||
using (ISession session = OpenSession()) | ||
using (ITransaction transaction = session.BeginTransaction()) | ||
{ | ||
var entityA = new PropertyEntityA() | ||
{ | ||
Name = "Name A", | ||
SerialNumber = 4321, | ||
SharedValue = "Some Value" | ||
}; | ||
var entityB = new PropertyEntityB() | ||
{ | ||
Name = "Name B", | ||
Description = "Some Description", | ||
SharedValue = "Another Value", | ||
AnotherString = "Another String" | ||
}; | ||
var entityC = new PropertyEntityC() | ||
{ | ||
Name = "Name C", | ||
Description = "Has Description", | ||
SharedValue = "Value", | ||
AnotherNumber = 42 | ||
}; | ||
|
||
var separateEntity = new SeparateEntity() | ||
{ | ||
SeparateEntityValue = 5432 | ||
}; | ||
|
||
var mainEntity = new MainEntity() | ||
{ | ||
Text = "Main Entity Text" | ||
}; | ||
var secondMainEntity = new MainEntity() | ||
{ | ||
Text = "Second Entity Text" | ||
}; | ||
session.Save(mainEntity); | ||
session.Save(secondMainEntity); | ||
entityA.MainEntity = mainEntity; | ||
entityB.MainEntity = mainEntity; | ||
entityC.MainEntity = secondMainEntity; | ||
separateEntity.MainEntity = secondMainEntity; | ||
session.Save(entityA); | ||
session.Save(entityB); | ||
session.Save(entityC); | ||
session.Save(separateEntity); | ||
|
||
//mainEntity.Properties.Add(entityA); | ||
//mainEntity.Properties.Add(entityB); | ||
session.Flush(); | ||
transaction.Commit(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (ISession session = OpenSession()) | ||
using (ITransaction transaction = session.BeginTransaction()) | ||
{ | ||
session.Delete("from System.Object"); | ||
|
||
session.Flush(); | ||
transaction.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void OfTypeWorksWithSingleEntityInterface() | ||
{ | ||
using (ISession session = OpenSession()) | ||
using (session.BeginTransaction()) | ||
{ | ||
var entityQuery = session.Query<IMainEntity>(); | ||
var result = | ||
entityQuery.Where(m => m.Properties.OfType<IPropertyEntityB>().Any()).ToList(); | ||
Assert.AreEqual(1, result.Count); | ||
} | ||
} | ||
|
||
[Test] | ||
public void OfTypeWorksWithUnrelatedInterface() | ||
{ | ||
using (ISession session = OpenSession()) | ||
using (session.BeginTransaction()) | ||
{ | ||
var entityQuery = session.Query<IMainEntity>(); | ||
var result = | ||
entityQuery.Where(m => m.Properties.OfType<IHasDescription>().Any()).ToList(); | ||
Assert.AreEqual(2, result.Count); | ||
} | ||
} | ||
|
||
[Test] | ||
public void CanQueryOfTypePropertyWithUnrelatedInterface() | ||
{ | ||
using (ISession session = OpenSession()) | ||
using (session.BeginTransaction()) | ||
{ | ||
var entityQuery = session.Query<IMainEntity>(); | ||
var result = | ||
entityQuery.Where(m => m.Properties.OfType<IHasDescription>().Any(d => d.Description == "Has Description")) | ||
.ToList(); | ||
Assert.AreEqual(1, result.Count); | ||
} | ||
} | ||
|
||
[Test] | ||
public void ImpossibleOfTypeReturnsNoResults() | ||
{ | ||
using (ISession session = OpenSession()) | ||
using (session.BeginTransaction()) | ||
{ | ||
var entityQuery = session.Query<IMainEntity>(); | ||
var result = | ||
entityQuery.Where(m => m.Properties.OfType<ISession>().Any()).ToList(); | ||
Assert.IsEmpty(result); | ||
} | ||
} | ||
|
||
[Test] | ||
public void ImpossibleMappedOfTypeReturnsNoResults() | ||
{ | ||
using (ISession session = OpenSession()) | ||
using (session.BeginTransaction()) | ||
{ | ||
var entityQuery = session.Query<IMainEntity>(); | ||
var result = | ||
entityQuery.Where(m => m.Properties.OfType<ISeparateEntity>().Any(se => se.SeparateEntityValue == 5432)).ToList(); | ||
Assert.IsEmpty(result); | ||
} | ||
} | ||
|
||
[Test] | ||
public void OfTypeAppliedToNonSubclassEntityStillWorks() | ||
{ | ||
using (ISession session = OpenSession()) | ||
using (session.BeginTransaction()) | ||
{ | ||
var entityQuery = session.Query<IMainEntity>(); | ||
var result = entityQuery.Where(m => m.SeparateEntities.OfType<SeparateEntity>().Any()).ToList(); | ||
Assert.AreEqual(1, result.Count); | ||
} | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/NHibernate.Test/NHSpecificTest/NH3845/Interfaces/IHasDescription.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,7 @@ | ||
namespace NHibernate.Test.NHSpecificTest.NH3845.Interfaces | ||
{ | ||
public interface IHasDescription | ||
{ | ||
string Description { get; set; } | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/NHibernate.Test/NHSpecificTest/NH3845/Interfaces/IMainEntity.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,12 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH3845.Interfaces | ||
{ | ||
public interface IMainEntity | ||
{ | ||
int MainEntityId { get; set; } | ||
string Text { get; set; } | ||
ISet<IPropertyEntityBase> Properties { get; } | ||
ISet<ISeparateEntity> SeparateEntities { get; } | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/NHibernate.Test/NHSpecificTest/NH3845/Interfaces/IPropertyEntityA.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,7 @@ | ||
namespace NHibernate.Test.NHSpecificTest.NH3845.Interfaces | ||
{ | ||
public interface IPropertyEntityA : IPropertyEntityBase | ||
{ | ||
int SerialNumber { get; set; } | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/NHibernate.Test/NHSpecificTest/NH3845/Interfaces/IPropertyEntityB.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,7 @@ | ||
namespace NHibernate.Test.NHSpecificTest.NH3845.Interfaces | ||
{ | ||
public interface IPropertyEntityB : IPropertyEntityBase, IHasDescription | ||
{ | ||
string AnotherString { get; set; } | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/NHibernate.Test/NHSpecificTest/NH3845/Interfaces/IPropertyEntityBase.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,10 @@ | ||
namespace NHibernate.Test.NHSpecificTest.NH3845.Interfaces | ||
{ | ||
public interface IPropertyEntityBase | ||
{ | ||
int PropertyEntityBaseId { get; set; } | ||
string Name { get; set; } | ||
string SharedValue { get; set; } | ||
IMainEntity MainEntity { get; set; } | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/NHibernate.Test/NHSpecificTest/NH3845/Interfaces/IPropertyEntityC.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,7 @@ | ||
namespace NHibernate.Test.NHSpecificTest.NH3845.Interfaces | ||
{ | ||
public interface IPropertyEntityC : IPropertyEntityBase, IHasDescription | ||
{ | ||
int AnotherNumber { get; set; } | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/NHibernate.Test/NHSpecificTest/NH3845/Interfaces/ISeparateEntity.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,9 @@ | ||
namespace NHibernate.Test.NHSpecificTest.NH3845.Interfaces | ||
{ | ||
public interface ISeparateEntity | ||
{ | ||
int SeparateEntityId { get; set; } | ||
IMainEntity MainEntity { get; set; } | ||
int SeparateEntityValue { get; set; } | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/NHibernate.Test/NHSpecificTest/NH3845/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,45 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" | ||
namespace="NHibernate.Test.NHSpecificTest.NH3845.Concrete"> | ||
<class name="MainEntity"> | ||
<id name="MainEntityId" type="Int32"> | ||
<generator class="native" /> | ||
</id> | ||
<property name="Text" /> | ||
<set name="Properties" cascade="all" inverse="true" lazy="true"> | ||
<key column="MainEntityId" /> | ||
<one-to-many class="PropertyEntityBase" /> | ||
</set> | ||
<set name="SeparateEntities" cascade="all" inverse="true" lazy="true"> | ||
<key column="MainEntityId" /> | ||
<one-to-many class="SeparateEntity" /> | ||
</set> | ||
</class> | ||
<class name="PropertyEntityBase" abstract="true"> | ||
<id name="PropertyEntityBaseId" type="Int32"> | ||
<generator class="enhanced-sequence" /> | ||
</id> | ||
<property name="Name" /> | ||
<property name="SharedValue" /> | ||
<many-to-one name="MainEntity" class="MainEntity" cascade="all" column="MainEntityId" /> | ||
<union-subclass name="PropertyEntityA"> | ||
<property name="SerialNumber" /> | ||
</union-subclass> | ||
<union-subclass name="PropertyEntityB"> | ||
<property name="Description" /> | ||
<property name="AnotherString" /> | ||
</union-subclass> | ||
<union-subclass name="PropertyEntityC"> | ||
<property name="Description" /> | ||
<property name="AnotherNumber" /> | ||
</union-subclass> | ||
</class> | ||
<class name="SeparateEntity"> | ||
<id name="SeparateEntityId" type="Int32"> | ||
<generator class="native" /> | ||
</id> | ||
<many-to-one name="MainEntity" class="MainEntity" cascade="all" column="MainEntityId" /> | ||
<property name="SeparateEntityValue" /> | ||
</class> | ||
</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
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 |
---|---|---|
|
@@ -416,7 +416,7 @@ public HqlFalse False() | |
return new HqlFalse(_factory); | ||
} | ||
|
||
public HqlIn In(HqlExpression itemExpression, HqlTreeNode source) | ||
public HqlIn In(HqlExpression itemExpression, params HqlTreeNode[] source) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've found the proper solution for not changing this. You need to use |
||
{ | ||
return new HqlIn(_factory, itemExpression, source); | ||
} | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C# 6 is not yet supported by our build engine, please change to using C#5