-
Notifications
You must be signed in to change notification settings - Fork 934
Fix property type retrieval for Composite User Type in LINQ #2877
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 all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
83ef1c7
Fix component type retrieval in LINQ
bahusoid cb37ef2
Simplify fix
bahusoid 6c39c16
Oversimplified
bahusoid bb8e98e
Merge branch '5.3.x' into gh2856
fredericDelaporte e12e488
Merge branch '5.3.x' into gh2856
fredericDelaporte 7422786
Merge branch '5.3.x' into gh2856
fredericDelaporte 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
55 changes: 55 additions & 0 deletions
55
src/NHibernate.Test/Async/NHSpecificTest/GH2856/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,55 @@ | ||
//------------------------------------------------------------------------------ | ||
// <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.GH2856 | ||
{ | ||
using System.Threading.Tasks; | ||
[TestFixture] | ||
public class FixtureAsync : BugTestCase | ||
{ | ||
protected override void OnSetUp() | ||
{ | ||
using (var s = Sfi.OpenSession()) | ||
using (var t = s.BeginTransaction()) | ||
{ | ||
s.Save(new Entity {Name = "Company", Phone = new PhoneNumber("745-555-1234"),}); | ||
s.Save(new Entity {Name = "Bob", Phone = new PhoneNumber("745-555-1234", "x123"),}); | ||
s.Save(new Entity {Name = "Jane", Phone = new PhoneNumber("745-555-1235"),}); | ||
s.Flush(); | ||
t.Commit(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var s = Sfi.OpenSession()) | ||
using (var t = s.BeginTransaction()) | ||
{ | ||
s.Delete("from Entity"); | ||
s.Flush(); | ||
t.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task CanDistinctOnCompositeUserTypeAsync() | ||
{ | ||
using (var s = OpenSession()) | ||
{ | ||
var numbers = await (s.Query<Entity>().Select(x => x.Phone.Ext).Distinct().ToListAsync()); | ||
Assert.That(numbers.Count, Is.EqualTo(2)); | ||
} | ||
} | ||
} | ||
} |
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.GH2856 | ||
{ | ||
public class Entity | ||
{ | ||
public int? Id { get; set; } | ||
public string Name { get; set; } | ||
public PhoneNumber Phone { 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,43 @@ | ||
using System.Linq; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH2856 | ||
{ | ||
[TestFixture] | ||
public class Fixture : BugTestCase | ||
{ | ||
protected override void OnSetUp() | ||
{ | ||
using (var s = Sfi.OpenSession()) | ||
using (var t = s.BeginTransaction()) | ||
{ | ||
s.Save(new Entity {Name = "Company", Phone = new PhoneNumber("745-555-1234"),}); | ||
s.Save(new Entity {Name = "Bob", Phone = new PhoneNumber("745-555-1234", "x123"),}); | ||
s.Save(new Entity {Name = "Jane", Phone = new PhoneNumber("745-555-1235"),}); | ||
s.Flush(); | ||
t.Commit(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var s = Sfi.OpenSession()) | ||
using (var t = s.BeginTransaction()) | ||
{ | ||
s.Delete("from Entity"); | ||
s.Flush(); | ||
t.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void CanDistinctOnCompositeUserType() | ||
{ | ||
using (var s = OpenSession()) | ||
{ | ||
var numbers = s.Query<Entity>().Select(x => x.Phone.Ext).Distinct().ToList(); | ||
Assert.That(numbers.Count, Is.EqualTo(2)); | ||
} | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/NHibernate.Test/NHSpecificTest/GH2856/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,13 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" namespace="NHibernate.Test.NHSpecificTest.GH2856"> | ||
<class name="Entity" table="a" lazy="false" optimistic-lock="dirty" dynamic-update="true"> | ||
<id name="Id" column="id" unsaved-value="null"> | ||
<generator class="native" /> | ||
</id> | ||
<property name="Name"/> | ||
<property name="Phone" type="NHibernate.Test.NHSpecificTest.GH2856.PhoneNumberUserType, NHibernate.Test"> | ||
<column name="PhoneNumber"/> | ||
<column name="PhoneExt"/> | ||
</property> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace NHibernate.Test.NHSpecificTest.GH2856 | ||
{ | ||
public class PhoneNumber | ||
{ | ||
public PhoneNumber(string number, string ext = null) | ||
{ | ||
Number = number; | ||
Ext = ext; | ||
} | ||
|
||
public string Number { get; } | ||
|
||
public string Ext { get; } | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
src/NHibernate.Test/NHSpecificTest/GH2856/PhoneNumberUserType.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,102 @@ | ||
using System; | ||
using System.Data.Common; | ||
using NHibernate.Engine; | ||
using NHibernate.Type; | ||
using NHibernate.UserTypes; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH2856 | ||
{ | ||
class PhoneNumberUserType : ICompositeUserType | ||
{ | ||
public string[] PropertyNames | ||
{ | ||
get { return new[] {"Number", "Ext"}; } | ||
} | ||
|
||
public IType[] PropertyTypes | ||
{ | ||
get { return new IType[] {NHibernateUtil.String, NHibernateUtil.String}; } | ||
} | ||
|
||
public object GetPropertyValue(object component, int property) | ||
{ | ||
PhoneNumber phone = (PhoneNumber) component; | ||
|
||
switch (property) | ||
{ | ||
case 0: return phone.Number; | ||
case 1: return phone.Ext; | ||
default: throw new NotImplementedException(); | ||
} | ||
} | ||
|
||
public void SetPropertyValue(object component, int property, object value) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public System.Type ReturnedClass | ||
{ | ||
get { return typeof(PhoneNumber); } | ||
} | ||
|
||
public new bool Equals(object x, object y) | ||
{ | ||
if (ReferenceEquals(x, null) && ReferenceEquals(y, null)) | ||
return true; | ||
|
||
if (ReferenceEquals(x, null) || ReferenceEquals(y, null)) | ||
return false; | ||
|
||
return x.Equals(y); | ||
} | ||
|
||
public int GetHashCode(object x) | ||
{ | ||
return x.GetHashCode(); | ||
} | ||
|
||
public object NullSafeGet(DbDataReader dr, string[] names, ISessionImplementor session, object owner) | ||
{ | ||
return dr.IsDBNull(dr.GetOrdinal(names[0])) | ||
? null | ||
: (object) new PhoneNumber( | ||
(string) NHibernateUtil.String.NullSafeGet(dr, names[0], session, owner), | ||
(string) NHibernateUtil.String.NullSafeGet(dr, names[1], session, owner)); | ||
} | ||
|
||
public void NullSafeSet(DbCommand cmd, object value, int index, bool[] settable, ISessionImplementor session) | ||
{ | ||
object number = value == null ? null : ((PhoneNumber) value).Number; | ||
object ext = value == null ? null : ((PhoneNumber) value).Ext; | ||
|
||
if (settable[0]) NHibernateUtil.String.NullSafeSet(cmd, number, index++, session); | ||
if (settable[1]) NHibernateUtil.String.NullSafeSet(cmd, ext, index, session); | ||
} | ||
|
||
public object DeepCopy(object value) | ||
{ | ||
return value; | ||
} | ||
|
||
public bool IsMutable | ||
{ | ||
get { return false; } | ||
} | ||
|
||
public object Disassemble(object value, ISessionImplementor session) | ||
{ | ||
return value; | ||
} | ||
|
||
public object Assemble(object cached, ISessionImplementor session, object owner) | ||
{ | ||
return cached; | ||
} | ||
|
||
public object Replace(object original, object target, ISessionImplementor session, object owner) | ||
{ | ||
return original; | ||
} | ||
} | ||
} |
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.
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.
EntityMetamodel also can't handle
ICompositeUserType
components. So why bother to use it at all if we can retrieve all info fromcomponentType
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.