コード例 #1
0
        /// <summary>
        /// Gets the cached primary key property for the entity.
        /// </summary>
        /// <typeparam name="TEntity">The type of the target entity.</typeparam>
        /// <param name="command">The target command.</param>
        /// <returns>The cached properties of the entity.</returns>
        public static IEnumerable <ClassProperty> Get <TEntity>(Command command = Command.None)
            where TEntity : class
        {
            var key        = $"{typeof(TEntity).FullName}.{command.ToString()}";
            var properties = (IEnumerable <ClassProperty>)null;

            if (m_cache.TryGetValue(key, out properties) == false)
            {
                properties = ClassExpression.GetProperties <TEntity>(command);
                m_cache.TryAdd(key, properties);
            }
            return(properties);
        }
コード例 #2
0
        /// <summary>
        /// Gets the cached primary key property for the entity.
        /// </summary>
        /// <typeparam name="TEntity">The type of the target entity.</typeparam>
        /// <returns>The cached properties of the entity.</returns>
        public static IEnumerable <ClassProperty> Get <TEntity>()
            where TEntity : class
        {
            var key        = typeof(TEntity).FullName;
            var properties = (IEnumerable <ClassProperty>)null;

            if (m_cache.TryGetValue(key, out properties) == false)
            {
                properties = ClassExpression.GetProperties <TEntity>();
                m_cache.TryAdd(key, properties);
            }
            return(properties);
        }
コード例 #3
0
        /// <summary>
        /// Gets the cached list of <see cref="ClassProperty"/> objects of the data entity.
        /// </summary>
        /// <typeparam name="TEntity">The type of the target entity.</typeparam>
        /// <returns>The cached list <see cref="ClassProperty"/> objects.</returns>
        public static IEnumerable <ClassProperty> Get <TEntity>()
            where TEntity : class
        {
            var type       = typeof(TEntity);
            var properties = (IEnumerable <ClassProperty>)null;
            var key        = type.FullName.GetHashCode();

            // Try get the value
            if (type.GetTypeInfo().IsGenericType == false && m_cache.TryGetValue(key, out properties) == false)
            {
                properties = ClassExpression.GetProperties <TEntity>();
                m_cache.TryAdd(key, properties);
            }

            // Return the value
            return(properties);
        }
コード例 #4
0
ファイル: DataEntityDataReader.cs プロジェクト: bank2u/RepoDb
        /// <summary>
        /// Populates the values of the array of the current values of the current row.
        /// </summary>
        /// <param name="values">The array variable on which to populate the data.</param>
        /// <returns></returns>
        public override int GetValues(object[] values)
        {
            ThrowExceptionIfNotAvailable();
            if (values == null)
            {
                throw new NullReferenceException("The values array must not be null.");
            }
            if (values.Length != FieldCount)
            {
                throw new InvalidOperationException($"The length of the array must be equals to the number of fields of the data entity (it should be {FieldCount}).");
            }
            var extracted = ClassExpression.GetPropertiesAndValues(Enumerator.Current).ToArray();

            for (var i = 0; i < Properties.Count; i++)
            {
                values[i] = extracted[i].Value;
            }
            return(FieldCount);
        }
コード例 #5
0
        /// <summary>
        /// Gets the cached list of <see cref="ClassProperty"/> objects of the data entity.
        /// </summary>
        /// <typeparam name="TEntity">The type of the target entity.</typeparam>
        /// <param name="dbSetting">The database setting that is currently in used.</param>
        /// <returns>The cached list <see cref="ClassProperty"/> objects.</returns>
        public static IEnumerable <ClassProperty> Get <TEntity>(IDbSetting dbSetting)
            where TEntity : class
        {
            var properties = (IEnumerable <ClassProperty>)null;
            var key        = typeof(TEntity).FullName.GetHashCode();

            // Add the DbSetting hashcode
            if (dbSetting != null)
            {
                key += dbSetting.GetHashCode();
            }

            // Try get the value
            if (m_cache.TryGetValue(key, out properties) == false)
            {
                properties = ClassExpression.GetProperties <TEntity>(dbSetting);
                m_cache.TryAdd(key, properties);
            }

            // Return the value
            return(properties);
        }