Пример #1
0
        /// <summary>
        /// Get the values of the natural id fields as known to the underlying
        /// database, or null if the entity has no natural id or there is no
        /// corresponding row.
        /// </summary>
        public async Task <object[]> GetNaturalIdSnapshotAsync(object id, IEntityPersister persister, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (!persister.HasNaturalIdentifier)
            {
                return(null);
            }

            // if the natural-id is marked as non-mutable, it is not retrieved during a
            // normal database-snapshot operation...
            int[]  props      = persister.NaturalIdentifierProperties;
            bool[] updateable = persister.PropertyUpdateability;
            bool   allNatualIdPropsAreUpdateable = true;

            for (int i = 0; i < props.Length; i++)
            {
                if (!updateable[props[i]])
                {
                    allNatualIdPropsAreUpdateable = false;
                    break;
                }
            }

            if (allNatualIdPropsAreUpdateable)
            {
                // do this when all the properties are updateable since there is
                // a certain likelihood that the information will already be
                // snapshot-cached.
                object[] entitySnapshot = await(GetDatabaseSnapshotAsync(id, persister, cancellationToken)).ConfigureAwait(false);
                if (entitySnapshot == NoRow)
                {
                    return(null);
                }
                object[] naturalIdSnapshot = new object[props.Length];
                for (int i = 0; i < props.Length; i++)
                {
                    naturalIdSnapshot[i] = entitySnapshot[props[i]];
                }
                return(naturalIdSnapshot);
            }
            else
            {
                return(await(persister.GetNaturalIdentifierSnapshotAsync(id, session, cancellationToken)).ConfigureAwait(false));
            }
        }