Skip to content

Commit 36c2079

Browse files
committed
fixup! Modified field interceptor to skip initialization of lazy properties when setting one
1 parent c9c5a64 commit 36c2079

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

src/NHibernate/Async/Engine/Cascade.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ public async Task CascadeOnAsync(IEntityPersister persister, object parent, obje
6060

6161
IType[] types = persister.PropertyTypes;
6262
CascadeStyle[] cascadeStyles = persister.PropertyCascadeStyles;
63-
ISet<string> uninitializedLazyProperties = persister.GetUninitializedLazyProperties(parent);
63+
var uninitializedLazyProperties = persister.GetUninitializedLazyProperties(parent);
6464
for (int i = 0; i < types.Length; i++)
6565
{
6666
CascadeStyle style = cascadeStyles[i];
6767
string propertyName = persister.PropertyNames[i];
68-
if (uninitializedLazyProperties.Contains(persister.PropertyNames[i]) && persister.PropertyLaziness[i] && !action.PerformOnLazyProperty)
68+
if (uninitializedLazyProperties.Contains(propertyName) && persister.PropertyLaziness[i] && !action.PerformOnLazyProperty)
6969
{
7070
//do nothing to avoid a lazy property initialization
7171
continue;

src/NHibernate/Async/Persister/Entity/AbstractEntityPersister.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -877,10 +877,7 @@ public async Task UpdateAsync(object id, object[] fields, int[] dirtyFields, boo
877877
if (entry == null && !IsMutable)
878878
throw new InvalidOperationException("Updating immutable entity that is not in session yet!");
879879

880-
if ((entityMetamodel.IsDynamicUpdate && dirtyFields != null) ||
881-
// When having a dirty lazy property and the entity is not yet initialized we have to use a dynamic update for it even if
882-
// it is disabled in order to have it updated.
883-
(GetUninitializedLazyProperties(obj).Count > 0 && dirtyFields?.Count(o => PropertyLaziness[o]) > 0))
880+
if (dirtyFields != null && (entityMetamodel.IsDynamicUpdate || HasDirtyLazyProperties(dirtyFields, obj)))
884881
{
885882
// For the case of dynamic-update="true", we need to generate the UPDATE SQL
886883
propsToUpdate = GetPropertiesToUpdate(dirtyFields, hasDirtyCollection);

src/NHibernate/Engine/Cascade.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ public void CascadeOn(IEntityPersister persister, object parent, object anything
113113

114114
IType[] types = persister.PropertyTypes;
115115
CascadeStyle[] cascadeStyles = persister.PropertyCascadeStyles;
116-
ISet<string> uninitializedLazyProperties = persister.GetUninitializedLazyProperties(parent);
116+
var uninitializedLazyProperties = persister.GetUninitializedLazyProperties(parent);
117117
for (int i = 0; i < types.Length; i++)
118118
{
119119
CascadeStyle style = cascadeStyles[i];
120120
string propertyName = persister.PropertyNames[i];
121-
if (uninitializedLazyProperties.Contains(persister.PropertyNames[i]) && persister.PropertyLaziness[i] && !action.PerformOnLazyProperty)
121+
if (uninitializedLazyProperties.Contains(propertyName) && persister.PropertyLaziness[i] && !action.PerformOnLazyProperty)
122122
{
123123
//do nothing to avoid a lazy property initialization
124124
continue;

src/NHibernate/Persister/Entity/AbstractEntityPersister.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3167,10 +3167,7 @@ public void Update(object id, object[] fields, int[] dirtyFields, bool hasDirtyC
31673167
if (entry == null && !IsMutable)
31683168
throw new InvalidOperationException("Updating immutable entity that is not in session yet!");
31693169

3170-
if ((entityMetamodel.IsDynamicUpdate && dirtyFields != null) ||
3171-
// When having a dirty lazy property and the entity is not yet initialized we have to use a dynamic update for it even if
3172-
// it is disabled in order to have it updated.
3173-
(GetUninitializedLazyProperties(obj).Count > 0 && dirtyFields?.Count(o => PropertyLaziness[o]) > 0))
3170+
if (dirtyFields != null && (entityMetamodel.IsDynamicUpdate || HasDirtyLazyProperties(dirtyFields, obj)))
31743171
{
31753172
// For the case of dynamic-update="true", we need to generate the UPDATE SQL
31763173
propsToUpdate = GetPropertiesToUpdate(dirtyFields, hasDirtyCollection);
@@ -3219,6 +3216,13 @@ public void Update(object id, object[] fields, int[] dirtyFields, bool hasDirtyC
32193216
}
32203217
}
32213218

3219+
private bool HasDirtyLazyProperties(int[] dirtyFields, object obj)
3220+
{
3221+
// When having a dirty lazy property and the entity is not yet initialized we have to use a dynamic update for
3222+
// it even if it is disabled in order to have it updated.
3223+
return GetUninitializedLazyProperties(obj).Count > 0 && dirtyFields.Any(o => PropertyLaziness[o]);
3224+
}
3225+
32223226
public object Insert(object[] fields, object obj, ISessionImplementor session)
32233227
{
32243228
int span = TableSpan;

0 commit comments

Comments
 (0)