Skip to content

Commit 22165b0

Browse files
committed
Eliminate usage of protected field uniqueKeyPropertyName.
1 parent f0644cf commit 22165b0

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

src/NHibernate/Async/Type/EntityType.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ protected internal async Task<object> GetReferenceValueAsync(object value, ISess
6565
else
6666
{
6767
IEntityPersister entityPersister = session.Factory.GetEntityPersister(GetAssociatedEntityName());
68-
object propertyValue = entityPersister.GetPropertyValue(value, uniqueKeyPropertyName);
68+
object propertyValue = entityPersister.GetPropertyValue(value, _uniqueKeyPropertyName);
6969

7070
// We now have the value of the property-ref we reference. However,
7171
// we need to dig a little deeper, as that property might also be
7272
// an entity type, in which case we need to resolve its identitifier
73-
IType type = entityPersister.GetPropertyType(uniqueKeyPropertyName);
73+
IType type = entityPersister.GetPropertyType(_uniqueKeyPropertyName);
7474
if (type.IsEntityType)
7575
{
7676
propertyValue = await (((EntityType) type).GetReferenceValueAsync(propertyValue, session, cancellationToken)).ConfigureAwait(false);
@@ -191,7 +191,7 @@ public override Task<object> ResolveIdentifierAsync(object value, ISessionImplem
191191
}
192192
else
193193
{
194-
return LoadByUniqueKeyAsync(GetAssociatedEntityName(), uniqueKeyPropertyName, value, session, cancellationToken);
194+
return LoadByUniqueKeyAsync(GetAssociatedEntityName(), _uniqueKeyPropertyName, value, session, cancellationToken);
195195
}
196196
}
197197
}

src/NHibernate/Type/EntityType.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ namespace NHibernate.Type
1717
[Serializable]
1818
public abstract partial class EntityType : AbstractType, IAssociationType
1919
{
20+
// Since v5.1
21+
[Obsolete("This field has no more usages in NHibernate and will be removed. Use RHSUniqueKeyPropertyName instead.")]
2022
protected readonly string uniqueKeyPropertyName;
23+
24+
private readonly string _uniqueKeyPropertyName;
2125
private readonly bool eager;
2226
private readonly string associatedEntityName;
2327
private readonly bool unwrapProxy;
@@ -37,8 +41,12 @@ public abstract partial class EntityType : AbstractType, IAssociationType
3741
/// </param>
3842
protected internal EntityType(string entityName, string uniqueKeyPropertyName, bool eager, bool unwrapProxy)
3943
{
40-
associatedEntityName = entityName;
44+
#pragma warning disable 618
4145
this.uniqueKeyPropertyName = uniqueKeyPropertyName;
46+
#pragma warning restore 618
47+
48+
associatedEntityName = entityName;
49+
_uniqueKeyPropertyName = uniqueKeyPropertyName;
4250
this.eager = eager;
4351
this.unwrapProxy = unwrapProxy;
4452
}
@@ -165,12 +173,12 @@ protected internal object GetReferenceValue(object value, ISessionImplementor se
165173
else
166174
{
167175
IEntityPersister entityPersister = session.Factory.GetEntityPersister(GetAssociatedEntityName());
168-
object propertyValue = entityPersister.GetPropertyValue(value, uniqueKeyPropertyName);
176+
object propertyValue = entityPersister.GetPropertyValue(value, _uniqueKeyPropertyName);
169177

170178
// We now have the value of the property-ref we reference. However,
171179
// we need to dig a little deeper, as that property might also be
172180
// an entity type, in which case we need to resolve its identitifier
173-
IType type = entityPersister.GetPropertyType(uniqueKeyPropertyName);
181+
IType type = entityPersister.GetPropertyType(_uniqueKeyPropertyName);
174182
if (type.IsEntityType)
175183
{
176184
propertyValue = ((EntityType) type).GetReferenceValue(propertyValue, session);
@@ -283,7 +291,7 @@ public override sealed object NullSafeGet(DbDataReader rs, string[] names, ISess
283291

284292
public bool IsUniqueKeyReference
285293
{
286-
get { return uniqueKeyPropertyName != null; }
294+
get { return _uniqueKeyPropertyName != null; }
287295
}
288296

289297
public abstract bool IsNullable { get; }
@@ -311,7 +319,7 @@ public IType GetIdentifierOrUniqueKeyType(IMapping factory)
311319
}
312320
else
313321
{
314-
IType type = factory.GetReferencedPropertyType(GetAssociatedEntityName(), uniqueKeyPropertyName);
322+
IType type = factory.GetReferencedPropertyType(GetAssociatedEntityName(), _uniqueKeyPropertyName);
315323
if (type.IsEntityType)
316324
{
317325
type = ((EntityType) type).GetIdentifierOrUniqueKeyType(factory);
@@ -333,7 +341,7 @@ public string GetIdentifierOrUniqueKeyPropertyName(IMapping factory)
333341
}
334342
else
335343
{
336-
return uniqueKeyPropertyName;
344+
return _uniqueKeyPropertyName;
337345
}
338346
}
339347

@@ -399,7 +407,7 @@ public override object ResolveIdentifier(object value, ISessionImplementor sessi
399407
}
400408
else
401409
{
402-
return LoadByUniqueKey(GetAssociatedEntityName(), uniqueKeyPropertyName, value, session);
410+
return LoadByUniqueKey(GetAssociatedEntityName(), _uniqueKeyPropertyName, value, session);
403411
}
404412
}
405413
}
@@ -438,7 +446,7 @@ public string LHSPropertyName
438446

439447
public string RHSUniqueKeyPropertyName
440448
{
441-
get { return uniqueKeyPropertyName; }
449+
get { return _uniqueKeyPropertyName; }
442450
}
443451

444452
public virtual string PropertyName
@@ -472,7 +480,7 @@ public override int GetHashCode(object x, ISessionFactoryImplementor factory)
472480

473481
public bool IsReferenceToPrimaryKey
474482
{
475-
get { return string.IsNullOrEmpty(uniqueKeyPropertyName); }
483+
get { return string.IsNullOrEmpty(_uniqueKeyPropertyName); }
476484
}
477485

478486
public string GetOnCondition(string alias, ISessionFactoryImplementor factory, IDictionary<string, IFilter> enabledFilters)

src/NHibernate/Type/ManyToOneType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public override object Hydrate(DbDataReader rs, string[] names, ISessionImplemen
9797
private void ScheduleBatchLoadIfNeeded(object id, ISessionImplementor session)
9898
{
9999
//cannot batch fetch by unique key (property-ref associations)
100-
if (uniqueKeyPropertyName == null && id != null)
100+
if (RHSUniqueKeyPropertyName == null && id != null)
101101
{
102102
IEntityPersister persister = session.Factory.GetEntityPersister(GetAssociatedEntityName());
103103
EntityKey entityKey = session.GenerateEntityKey(id, persister);

0 commit comments

Comments
 (0)