/// <summary> /// Is the given property name a reference to the primary key of the associated /// entity construed by the given entity type? /// For example, consider a fragment like order.customer.id /// (where order is a from-element alias). Here, we'd have: /// propertyName = "id" AND /// owningType = ManyToOneType(Customer) /// and are being asked to determine whether "customer.id" is a reference /// to customer's PK... /// </summary> /// <param name="propertyName">The name of the property to check.</param> /// <param name="owningType">The type represeting the entity "owning" the property</param> /// <returns>True if propertyName references the entity's (owningType->associatedEntity) primary key; false otherwise.</returns> private bool IsReferenceToPrimaryKey(string propertyName, EntityType owningType) { IEntityPersister persister = SessionFactoryHelper.Factory.GetEntityPersister(owningType.GetAssociatedEntityName()); if (persister.EntityMetamodel.HasNonIdentifierPropertyNamedId) { // only the identifier property field name can be a reference to the associated entity's PK... return(propertyName == persister.IdentifierPropertyName && owningType.IsReferenceToPrimaryKey); } // here, we have two possibilities: // 1) the property-name matches the explicitly identifier property name // 2) the property-name matches the implicit 'id' property name if (EntityPersister.EntityID == propertyName) { // the referenced node text is the special 'id' return(owningType.IsReferenceToPrimaryKey); } string keyPropertyName = SessionFactoryHelper.GetIdentifierOrUniqueKeyPropertyName(owningType); return(keyPropertyName != null && keyPropertyName == propertyName && owningType.IsReferenceToPrimaryKey); }