Example #1
0
            /// <summary>
            /// Gets the <see cref="IPropertyReflector"/> properties that make up the unique key (lazy-loaded and cached for performance).
            /// </summary>
            /// <param name="ier">The parent <see cref="IEntityReflector"/>.</param>
            /// <returns>The <see cref="IPropertyReflector"/> properties.</returns>
            public IPropertyReflector[] GetPropertyReflectors(IEntityReflector ier)
            {
                if (propertyReflectors != null)
                {
                    return(propertyReflectors);
                }

                lock (_lock)
                {
                    if (propertyReflectors == null)
                    {
                        var prs = new IPropertyReflector[Properties.Length];
                        for (int i = 0; i < Properties.Length; i++)
                        {
                            prs[i] = ier.GetProperty(Properties[i]);
                            if (prs[i] == null)
                            {
                                // Special case where the unique key may be a reference data type; i.e. points to the 'NameSid' property.
                                prs[i] = ier.GetProperty(Properties[i] + "Sid");
                                if (prs[i] == null)
                                {
                                    throw new InvalidOperationException($"Type '{ier.Type.Name}' references a UniqueKey Property '{Properties[i]}' that does not exist.");
                                }
                            }
                        }

                        propertyReflectors = prs;
                    }
                }

                return(propertyReflectors);
            }