diff --git a/src/NHibernate.Test/Async/FetchLazyProperties/FetchLazyPropertiesFixture.cs b/src/NHibernate.Test/Async/FetchLazyProperties/FetchLazyPropertiesFixture.cs index 8fe1e68ba81..67b5558ad1f 100644 --- a/src/NHibernate.Test/Async/FetchLazyProperties/FetchLazyPropertiesFixture.cs +++ b/src/NHibernate.Test/Async/FetchLazyProperties/FetchLazyPropertiesFixture.cs @@ -945,6 +945,26 @@ public async Task TestFetchAfterEntityIsInitializedAsync(bool readOnly) Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Formula"), Is.True); } + [TestCase(true)] + [TestCase(false)] + public async Task TestFetchAllPropertiesAfterEntityIsInitializedAsync(bool readOnly) + { + Person person; + using(var s = OpenSession()) + using(var tx = s.BeginTransaction()) + { + person = await (s.CreateQuery("from Person where Id = 1").SetReadOnly(readOnly).UniqueResultAsync()); + var image = person.Image; + person = await (s.CreateQuery("from Person fetch all properties where Id = 1").SetReadOnly(readOnly).UniqueResultAsync()); + + await (tx.CommitAsync()); + } + + Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Image"), Is.True); + Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Address"), Is.True); + Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Formula"), Is.True); + } + [Test] public async Task TestHqlCrossJoinFetchFormulaAsync() { diff --git a/src/NHibernate.Test/FetchLazyProperties/FetchLazyPropertiesFixture.cs b/src/NHibernate.Test/FetchLazyProperties/FetchLazyPropertiesFixture.cs index 49a75c4b107..8e01d600671 100644 --- a/src/NHibernate.Test/FetchLazyProperties/FetchLazyPropertiesFixture.cs +++ b/src/NHibernate.Test/FetchLazyProperties/FetchLazyPropertiesFixture.cs @@ -934,6 +934,26 @@ public void TestFetchAfterEntityIsInitialized(bool readOnly) Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Formula"), Is.True); } + [TestCase(true)] + [TestCase(false)] + public void TestFetchAllPropertiesAfterEntityIsInitialized(bool readOnly) + { + Person person; + using(var s = OpenSession()) + using(var tx = s.BeginTransaction()) + { + person = s.CreateQuery("from Person where Id = 1").SetReadOnly(readOnly).UniqueResult(); + var image = person.Image; + person = s.CreateQuery("from Person fetch all properties where Id = 1").SetReadOnly(readOnly).UniqueResult(); + + tx.Commit(); + } + + Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Image"), Is.True); + Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Address"), Is.True); + Assert.That(NHibernateUtil.IsPropertyInitialized(person, "Formula"), Is.True); + } + [Test] public void TestHqlCrossJoinFetchFormula() { diff --git a/src/NHibernate/Async/Persister/Entity/AbstractEntityPersister.cs b/src/NHibernate/Async/Persister/Entity/AbstractEntityPersister.cs index 1d466b213e6..09f2076dd3d 100644 --- a/src/NHibernate/Async/Persister/Entity/AbstractEntityPersister.cs +++ b/src/NHibernate/Async/Persister/Entity/AbstractEntityPersister.cs @@ -87,7 +87,12 @@ async Task InternalInitializeLazyPropertiesAsync() int[] lazyIndexes; if (allLazyProperties) { - lazyIndexes = indexes = lazyPropertyNumbers; + indexes = lazyPropertyNumbers; + lazyIndexes = new int[lazyPropertyNumbers.Length]; + for(var i = 0; i < lazyIndexes.Length; i++) + { + lazyIndexes[i] = i; + } } else { diff --git a/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs b/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs index 924da726cc1..78afb6e2b09 100644 --- a/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs +++ b/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs @@ -1413,7 +1413,12 @@ public void InitializeLazyProperties( int[] lazyIndexes; if (allLazyProperties) { - lazyIndexes = indexes = lazyPropertyNumbers; + indexes = lazyPropertyNumbers; + lazyIndexes = new int[lazyPropertyNumbers.Length]; + for(var i = 0; i < lazyIndexes.Length; i++) + { + lazyIndexes[i] = i; + } } else {