-
Notifications
You must be signed in to change notification settings - Fork 935
Fix fetching lazy component on not mapped interface #3320
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 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
15bde0a
Test case
bahusoid 8bae384
Generate async files
github-actions[bot] d3ad54f
Fix
bahusoid 5c55532
Fix SqlServerCe
bahusoid 10770aa
Generate async files
github-actions[bot] 5dad3da
Add test case with multiple entities returned by interface
bahusoid d0084ea
Fix
bahusoid 7c716ce
Merge branch '5.4.x' into gh3289
bahusoid c8e4e83
Generate async files
github-actions[bot] b389372
test clean up
bahusoid af36c54
Generate async files
github-actions[bot] 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
94 changes: 94 additions & 0 deletions
94
src/NHibernate.Test/Async/NHSpecificTest/GH3289/FixtureByCode.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,94 @@ | ||
//------------------------------------------------------------------------------ | ||
// <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 NHibernate.Cfg.MappingSchema; | ||
using NHibernate.Linq; | ||
using NHibernate.Mapping.ByCode; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH3289 | ||
{ | ||
using System.Threading.Tasks; | ||
[TestFixture] | ||
public class ByCodeFixtureAsync : TestCaseMappingByCode | ||
{ | ||
protected override HbmMapping GetMappings() | ||
{ | ||
var mapper = new ModelMapper(); | ||
mapper.Class<Entity>(rc => | ||
{ | ||
rc.Id(x => x.Id, m => m.Generator(Generators.Identity)); | ||
rc.Property(x => x.Name); | ||
rc.Component(x => x.Component); | ||
}); | ||
mapper.JoinedSubclass<SubEntity>(rc => | ||
{ | ||
rc.EntityName(typeof(ISubEntity).FullName); | ||
rc.Key(k => k.Column("Id")); | ||
rc.Property(x => x.SomeProperty); | ||
}); | ||
mapper.Component<Component>(rc => | ||
{ | ||
rc.Property(x => x.Field); | ||
rc.Lazy(true); | ||
}); | ||
|
||
return mapper.CompileMappingForAllExplicitlyAddedEntities(); | ||
} | ||
|
||
protected override void OnSetUp() | ||
{ | ||
using var session = OpenSession(); | ||
using var transaction = session.BeginTransaction(); | ||
var e1 = new SubEntity { Name = "Jim" }; | ||
session.Save(e1); | ||
|
||
transaction.Commit(); | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using var session = OpenSession(); | ||
using var transaction = session.BeginTransaction(); | ||
|
||
if (Dialect.SupportsTemporaryTables) | ||
session.CreateQuery("delete from System.Object").ExecuteUpdate(); | ||
else | ||
session.Delete("from System.Object"); | ||
|
||
transaction.Commit(); | ||
} | ||
|
||
[Test] | ||
public async Task TestSubEntityInterfaceWithFetchIsPropertyInitializedAsync() | ||
{ | ||
using var session = OpenSession(); | ||
var data = await (session.Query<ISubEntity>() | ||
.Fetch(e => e.Component) | ||
.ToListAsync()); | ||
var result = NHibernateUtil.IsPropertyInitialized(data[0], "Component"); | ||
|
||
Assert.That(result, Is.True); | ||
} | ||
|
||
[Test] | ||
public async Task TestSubEntityWithFetchIsPropertyInitializedAsync() | ||
{ | ||
using var session = OpenSession(); | ||
var data = await (session.Query<SubEntity>() | ||
.Fetch(e => e.Component) | ||
.ToListAsync()); | ||
var result = NHibernateUtil.IsPropertyInitialized(data[0], "Component"); | ||
|
||
Assert.That(result, Is.True); | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
src/NHibernate.Test/NHSpecificTest/GH3289/FixtureByCode.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,83 @@ | ||
using System.Linq; | ||
using NHibernate.Cfg.MappingSchema; | ||
using NHibernate.Linq; | ||
using NHibernate.Mapping.ByCode; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH3289 | ||
{ | ||
[TestFixture] | ||
public class ByCodeFixture : TestCaseMappingByCode | ||
{ | ||
protected override HbmMapping GetMappings() | ||
{ | ||
var mapper = new ModelMapper(); | ||
mapper.Class<Entity>(rc => | ||
{ | ||
rc.Id(x => x.Id, m => m.Generator(Generators.Identity)); | ||
rc.Property(x => x.Name); | ||
rc.Component(x => x.Component); | ||
}); | ||
mapper.JoinedSubclass<SubEntity>(rc => | ||
{ | ||
rc.EntityName(typeof(ISubEntity).FullName); | ||
rc.Key(k => k.Column("Id")); | ||
rc.Property(x => x.SomeProperty); | ||
}); | ||
mapper.Component<Component>(rc => | ||
{ | ||
rc.Property(x => x.Field); | ||
rc.Lazy(true); | ||
}); | ||
|
||
return mapper.CompileMappingForAllExplicitlyAddedEntities(); | ||
} | ||
|
||
protected override void OnSetUp() | ||
{ | ||
using var session = OpenSession(); | ||
using var transaction = session.BeginTransaction(); | ||
var e1 = new SubEntity { Name = "Jim" }; | ||
session.Save(e1); | ||
|
||
transaction.Commit(); | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using var session = OpenSession(); | ||
using var transaction = session.BeginTransaction(); | ||
|
||
if (Dialect.SupportsTemporaryTables) | ||
session.CreateQuery("delete from System.Object").ExecuteUpdate(); | ||
else | ||
session.Delete("from System.Object"); | ||
|
||
transaction.Commit(); | ||
} | ||
|
||
[Test] | ||
public void TestSubEntityInterfaceWithFetchIsPropertyInitialized() | ||
{ | ||
using var session = OpenSession(); | ||
var data = session.Query<ISubEntity>() | ||
.Fetch(e => e.Component) | ||
.ToList(); | ||
var result = NHibernateUtil.IsPropertyInitialized(data[0], "Component"); | ||
|
||
Assert.That(result, Is.True); | ||
} | ||
|
||
[Test] | ||
public void TestSubEntityWithFetchIsPropertyInitialized() | ||
{ | ||
using var session = OpenSession(); | ||
var data = session.Query<SubEntity>() | ||
.Fetch(e => e.Component) | ||
.ToList(); | ||
var result = NHibernateUtil.IsPropertyInitialized(data[0], "Component"); | ||
|
||
Assert.That(result, Is.True); | ||
} | ||
} | ||
} |
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,31 @@ | ||
namespace NHibernate.Test.NHSpecificTest.GH3289 | ||
{ | ||
public interface IEntity | ||
{ | ||
int Id { get; set; } | ||
string Name { get; set; } | ||
Component Component { get; set; } | ||
} | ||
|
||
public interface ISubEntity : IEntity | ||
{ | ||
public bool SomeProperty { get; set; } | ||
} | ||
|
||
public class Entity : IEntity | ||
{ | ||
public virtual int Id { get; set; } | ||
public virtual string Name { get; set; } | ||
public virtual Component Component { get; set; } | ||
} | ||
|
||
public class SubEntity : Entity, ISubEntity | ||
{ | ||
public virtual bool SomeProperty { get; set; } | ||
} | ||
|
||
public class Component | ||
{ | ||
public virtual string Field { 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
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.