示例#1
0
        /// <summary>
        /// Gets a collection of primary keys for the specified type.
        /// </summary>
        /// <param name="source">The repository conventions.</param>
        /// <param name="type">The type.</param>
        /// <returns>The collection of primary keys for the specified type.</returns>
        public static PropertyInfo[] GetPrimaryKeyPropertyInfos([NotNull] this IRepositoryConventions source, [NotNull] Type type)
        {
            Guard.NotNull(type, nameof(type));

            var result = EnsureCallback(
                source.PrimaryKeysCallback,
                nameof(source.PrimaryKeysCallback))(type) ?? new PropertyInfo[0];

            return(result);
        }
示例#2
0
        /// <summary>
        /// Gets a collection of primary keys for the specified type.
        /// </summary>
        /// <param name="source">The repository conventions.</param>
        /// <param name="type">The type.</param>
        /// <returns>The collection of primary keys for the specified type.</returns>
        public static PropertyInfo[] GetPrimaryKeyPropertyInfos([NotNull] this IRepositoryConventions source, [NotNull] Type type)
        {
            EnsureOwner(source);
            Guard.NotNull(type, nameof(type));

            var store = _primaryKeyPropertyInfosCache.GetOrAdd(source.Owner, new ConcurrentDictionary <Type, PropertyInfo[]>());

            if (!store.TryGetValue(type, out var result))
            {
                store[type] = result = EnsureCallback(
                    source.PrimaryKeysCallback,
                    nameof(source.PrimaryKeysCallback))(type) ?? new PropertyInfo[0];
            }

            return(result);
        }
示例#3
0
        /// <summary>
        /// Determines whether the specified property is defined as identity.
        /// </summary>
        /// <param name="source">The configurable conventions.</param>
        /// <param name="pi">The property.</param>
        /// <returns><c>true</c> if column is defined as identity.; otherwise, <c>false</c>.</returns>
        public static bool IsColumnIdentity([NotNull] this IRepositoryConventions source, [NotNull] PropertyInfo pi)
        {
            EnsureOwner(source);
            Guard.NotNull(pi, nameof(pi));

            var store = _isColumnIdentityCallback.GetOrAdd(source.Owner, new ConcurrentDictionary <PropertyInfo, bool>());

            if (!store.TryGetValue(pi, out var result))
            {
                store[pi] = result = EnsureCallback(
                    source.IsColumnIdentityCallback,
                    nameof(source.IsColumnIdentityCallback))(pi);
            }

            return(result);
        }
示例#4
0
        /// <summary>
        /// Gets a column order for the specified property.
        /// </summary>
        /// <param name="source">The configurable conventions.</param>
        /// <param name="pi">The property.</param>
        /// <returns>The column order for the specified property.</returns>
        public static int?GetColumnOrder([NotNull] this IRepositoryConventions source, [NotNull] PropertyInfo pi)
        {
            EnsureOwner(source);
            Guard.NotNull(pi, nameof(pi));

            var store = _columnOrderCache.GetOrAdd(source.Owner, new ConcurrentDictionary <PropertyInfo, int?>());

            if (!store.TryGetValue(pi, out var result))
            {
                store[pi] = result = EnsureCallback(
                    source.ColumnOrderCallback,
                    nameof(source.ColumnOrderCallback))(pi);
            }

            return(result);
        }
示例#5
0
        /// <summary>
        /// Gets a table name for the specified type.
        /// </summary>
        /// <param name="source">The configurable conventions.</param>
        /// <param name="type">The type.</param>
        /// <returns>The table name for the specified type.</returns>
        public static string GetTableName([NotNull] this IRepositoryConventions source, [NotNull] Type type)
        {
            EnsureOwner(source);
            Guard.NotNull(type, nameof(type));

            var store = _tableNameCache.GetOrAdd(source.Owner, new ConcurrentDictionary <Type, string>());

            if (!store.TryGetValue(type, out var result))
            {
                store[type] = result = EnsureCallback(
                    source.TableNameCallback,
                    nameof(source.TableNameCallback))(type);
            }

            return(result);
        }
示例#6
0
        /// <summary>
        /// Gets a collection of foreign key properties that matches the specified foreign type.
        /// </summary>
        /// <param name="source">The repository conventions.</param>
        /// <param name="sourceType">The source type.</param>
        /// <param name="foreignType">The foreign type to match.</param>
        /// <returns>The collection of foreign key properties that matches the specified foreign type.</returns>
        public static PropertyInfo[] GetForeignKeyPropertyInfos([NotNull] this IRepositoryConventions source, [NotNull] Type sourceType, [NotNull] Type foreignType)
        {
            EnsureOwner(source);
            Guard.NotNull(sourceType, nameof(sourceType));
            Guard.NotNull(foreignType, nameof(foreignType));

            var store = _foreignKeyPropertyInfosCache.GetOrAdd(source.Owner, new ConcurrentDictionary <Tuple <Type, Type>, PropertyInfo[]>());
            var key   = Tuple.Create(sourceType, foreignType);

            if (!store.TryGetValue(key, out var result))
            {
                store[key] = result = EnsureCallback(
                    source.ForeignKeysCallback,
                    nameof(source.ForeignKeysCallback))(sourceType, foreignType) ?? new PropertyInfo[0];
            }

            return(result);
        }
 /// <summary>
 /// Gets a collection of primary keys for the specified type.
 /// </summary>
 /// <param name="source">The repository conventions.</param>
 /// <param name="type">The type.</param>
 /// <returns>The collection of primary keys for the specified type.</returns>
 public static PropertyInfo[] GetPrimaryKeyPropertyInfos([NotNull] this IRepositoryConventions source, [NotNull] Type type)
 => EnsureCallback(
     Guard.NotNull(source, nameof(source)).PrimaryKeysCallback,
     nameof(source.PrimaryKeysCallback))(Guard.NotNull(type, nameof(type))) ?? new PropertyInfo[0];
 /// <summary>
 /// Determines whether the specified property is defined as identity.
 /// </summary>
 /// <param name="source">The configurable conventions.</param>
 /// <param name="pi">The property.</param>
 /// <returns><c>true</c> if column is defined as identity.; otherwise, <c>false</c>.</returns>
 public static bool IsColumnIdentity([NotNull] this IRepositoryConventions source, [NotNull] PropertyInfo pi)
 => EnsureCallback(
     Guard.NotNull(source, nameof(source)).IsColumnIdentityCallback,
     nameof(source.IsColumnIdentityCallback))(Guard.NotNull(pi, nameof(pi)));
 /// <summary>
 /// Gets a column order for the specified property.
 /// </summary>
 /// <param name="source">The configurable conventions.</param>
 /// <param name="pi">The property.</param>
 /// <returns>The column order for the specified property.</returns>
 public static int?GetColumnOrder([NotNull] this IRepositoryConventions source, [NotNull] PropertyInfo pi)
 => EnsureCallback(
     Guard.NotNull(source, nameof(source)).ColumnOrderCallback,
     nameof(source.ColumnOrderCallback))(Guard.NotNull(pi, nameof(pi)));
 /// <summary>
 /// Gets a table name for the specified type.
 /// </summary>
 /// <param name="source">The configurable conventions.</param>
 /// <param name="type">The type.</param>
 /// <returns>The table name for the specified type.</returns>
 public static string GetTableName([NotNull] this IRepositoryConventions source, [NotNull] Type type)
 => EnsureCallback(
     Guard.NotNull(source, nameof(source)).TableNameCallback,
     nameof(source.TableNameCallback))(Guard.NotNull(type, nameof(type)));
 /// <summary>
 /// Gets a collection of foreign key properties that matches the specified foreign type.
 /// </summary>
 /// <param name="source">The repository conventions.</param>
 /// <param name="sourceType">The source type.</param>
 /// <param name="foreignType">The foreign type to match.</param>
 /// <returns>The collection of foreign key properties that matches the specified foreign type.</returns>
 public static PropertyInfo[] GetForeignKeyPropertyInfos([NotNull] this IRepositoryConventions source, [NotNull] Type sourceType, [NotNull] Type foreignType)
 => EnsureCallback(
     Guard.NotNull(source, nameof(source)).ForeignKeysCallback,
     nameof(source.ForeignKeysCallback))(Guard.NotNull(sourceType, nameof(sourceType)), Guard.NotNull(foreignType, nameof(foreignType))) ?? new PropertyInfo[0];