Skip to content

Commit c6e3128

Browse files
committed
Eliminate usage of protected field uniqueKeyPropertyName.
1 parent b8d7014 commit c6e3128

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-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);
@@ -190,7 +190,7 @@ public override Task<object> ResolveIdentifierAsync(object value, ISessionImplem
190190
}
191191
else
192192
{
193-
return LoadByUniqueKeyAsync(GetAssociatedEntityName(), uniqueKeyPropertyName, value, session, cancellationToken);
193+
return LoadByUniqueKeyAsync(GetAssociatedEntityName(), _uniqueKeyPropertyName, value, session, cancellationToken);
194194
}
195195
}
196196
catch (Exception ex)

src/NHibernate/Type/EntityType.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +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;
2123

24+
private readonly string _uniqueKeyPropertyName;
2225
private readonly bool _eager;
2326
private readonly string _associatedEntityName;
2427
private readonly bool _unwrapProxy;
@@ -38,8 +41,12 @@ public abstract partial class EntityType : AbstractType, IAssociationType
3841
/// </param>
3942
protected internal EntityType(string entityName, string uniqueKeyPropertyName, bool eager, bool unwrapProxy)
4043
{
41-
_associatedEntityName = entityName;
44+
#pragma warning disable 618
4245
this.uniqueKeyPropertyName = uniqueKeyPropertyName;
46+
#pragma warning restore 618
47+
48+
_associatedEntityName = entityName;
49+
_uniqueKeyPropertyName = uniqueKeyPropertyName;
4350
_eager = eager;
4451
_unwrapProxy = unwrapProxy;
4552
}
@@ -163,12 +170,12 @@ protected internal object GetReferenceValue(object value, ISessionImplementor se
163170
else
164171
{
165172
IEntityPersister entityPersister = session.Factory.GetEntityPersister(GetAssociatedEntityName());
166-
object propertyValue = entityPersister.GetPropertyValue(value, uniqueKeyPropertyName);
173+
object propertyValue = entityPersister.GetPropertyValue(value, _uniqueKeyPropertyName);
167174

168175
// We now have the value of the property-ref we reference. However,
169176
// we need to dig a little deeper, as that property might also be
170177
// an entity type, in which case we need to resolve its identitifier
171-
IType type = entityPersister.GetPropertyType(uniqueKeyPropertyName);
178+
IType type = entityPersister.GetPropertyType(_uniqueKeyPropertyName);
172179
if (type.IsEntityType)
173180
{
174181
propertyValue = ((EntityType) type).GetReferenceValue(propertyValue, session);
@@ -272,7 +279,7 @@ public sealed override object NullSafeGet(DbDataReader rs, string[] names, ISess
272279

273280
public bool IsUniqueKeyReference
274281
{
275-
get { return uniqueKeyPropertyName != null; }
282+
get { return _uniqueKeyPropertyName != null; }
276283
}
277284

278285
public abstract bool IsNullable { get; }
@@ -300,7 +307,7 @@ public IType GetIdentifierOrUniqueKeyType(IMapping factory)
300307
}
301308
else
302309
{
303-
IType type = factory.GetReferencedPropertyType(GetAssociatedEntityName(), uniqueKeyPropertyName);
310+
IType type = factory.GetReferencedPropertyType(GetAssociatedEntityName(), _uniqueKeyPropertyName);
304311
if (type.IsEntityType)
305312
{
306313
type = ((EntityType) type).GetIdentifierOrUniqueKeyType(factory);
@@ -322,7 +329,7 @@ public string GetIdentifierOrUniqueKeyPropertyName(IMapping factory)
322329
}
323330
else
324331
{
325-
return uniqueKeyPropertyName;
332+
return _uniqueKeyPropertyName;
326333
}
327334
}
328335

@@ -387,7 +394,7 @@ public override object ResolveIdentifier(object value, ISessionImplementor sessi
387394
}
388395
else
389396
{
390-
return LoadByUniqueKey(GetAssociatedEntityName(), uniqueKeyPropertyName, value, session);
397+
return LoadByUniqueKey(GetAssociatedEntityName(), _uniqueKeyPropertyName, value, session);
391398
}
392399
}
393400

@@ -420,7 +427,7 @@ public string GetAssociatedEntityName()
420427

421428
public string LHSPropertyName => null;
422429

423-
public string RHSUniqueKeyPropertyName => uniqueKeyPropertyName;
430+
public string RHSUniqueKeyPropertyName => _uniqueKeyPropertyName;
424431

425432
public virtual string PropertyName => null;
426433

@@ -448,7 +455,7 @@ public override int GetHashCode(object x, ISessionFactoryImplementor factory)
448455

449456
public abstract bool IsAlwaysDirtyChecked { get; }
450457

451-
public bool IsReferenceToPrimaryKey => string.IsNullOrEmpty(uniqueKeyPropertyName);
458+
public bool IsReferenceToPrimaryKey => string.IsNullOrEmpty(_uniqueKeyPropertyName);
452459

453460
public string GetOnCondition(string alias, ISessionFactoryImplementor factory, IDictionary<string, IFilter> enabledFilters)
454461
{

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)