コード例 #1
0
 public static object GetSum(IEntityField2 field, IRelationPredicateBucket filter)
 {
     using (DataAccessAdapter adapter = DataAccessAdapterManagerBase.CreateAdapter())
     {
         return(adapter.GetScalar(field, null, AggregateFunction.Sum, filter.PredicateExpression, null, filter.Relations));
     }
 }
コード例 #2
0
        private static object ConvertStringToFieldValue(IEntityField2 field, string fieldValueStr)
        {
            var dataValueStr = fieldValueStr.Trim('\'', '\"');
            var dataType     = field.DataType;

            if (dataType.IsGenericType && dataType.GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                if (string.IsNullOrEmpty(fieldValueStr))
                {
                    return(null); // it's ok to return null for nullable types
                }
                dataType = dataType.GenericTypeArguments[0];
            }
            object dataValue     = null;
            var    cannotConvert = true;

            if (CanChangeType(fieldValueStr, dataType))
            {
                try
                {
                    dataValue     = Convert.ChangeType(dataValueStr, dataType);
                    cannotConvert = false;
                }
                catch
                {
                }
            }
            if (cannotConvert)
            {
                throw new ArgumentException(string.Format("Value '{0}' cannot be converted to type {1}.", dataValueStr, dataType));
            }
            return(dataValue);
        }
コード例 #3
0
        /// <summary>
        /// Gets a collection of Products sorted by the passed in filed name, and direction of sort.
        /// </summary>
        /// <param name="sortOnField">field name to sort upon</param>
        /// <param name="direction">direction of sort</param>
        /// <returns>a sorted products collection</returns>
        /// <remarks>Shows how to use message parameters to specify sorting.
        /// </remarks>
        public IEntityCollection2 GetProductsSortedBy(string sortOnField, SortOperator direction)
        {
            EntityCollection toReturn = new EntityCollection(new ProductsEntityFactory());

            ProductsEntity product   = new ProductsEntity();
            SortExpression sorter    = null;
            IEntityField2  sortField = product.Fields[sortOnField];

            if (sortField != null)
            {
                sorter = new SortExpression(new SortClause(sortField, null, direction));
            }

            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                // fetch all products, sorted on the sort expression passed in
                adapter.FetchEntityCollection(toReturn, null, 0, sorter);
            }
            return(toReturn);
        }
コード例 #4
0
        private static object ConvertStringToFieldValue(IEntityField2 field, string fieldValueStr)
        {
            var dataValueStr = fieldValueStr.Trim('\'', '\"');
            var dataType = field.DataType;
            if (dataType.IsGenericType && dataType.GetGenericTypeDefinition() == typeof(Nullable<>))
            {
                if (string.IsNullOrEmpty(fieldValueStr))
                    return null; // it's ok to return null for nullable types

                dataType = dataType.GenericTypeArguments[0];
            }
            object dataValue = null;
            var cannotConvert = true;
            if (CanChangeType(fieldValueStr, dataType))
            {
                try
                {
                    dataValue = Convert.ChangeType(dataValueStr, dataType);
                    cannotConvert = false;
                }
                catch
                {
                }
            }
            if (cannotConvert)
                throw new ArgumentException(string.Format("Value '{0}' cannot be converted to type {1}.", dataValueStr, dataType));
            return dataValue;
        }
コード例 #5
0
 /// <summary>
 /// Retrieves the persistence info for the field passed in. 
 /// </summary>
 /// <param name="field">Field which fieldpersistence info has to be retrieved</param>
 /// <returns>the requested persistence information</returns>
 protected override IFieldPersistenceInfo GetFieldPersistenceInfo(IEntityField2 field)
 {
     IFieldPersistenceInfo persistenceInfo = PersistenceInfoFactory.GetFieldPersistenceInfo(field.ContainingObjectName, field.Name);
     InsertPersistenceInfoObjects(field.ExpressionToApply);
     return persistenceInfo;
 }
コード例 #6
0
        /// <summary>
        /// Gets the source column name for an <see cref="IEntityField2"/> in the persistent storage.
        /// </summary>
        /// <param name="field">The field to get the column name for.</param>
        /// <returns>Returns the source column name for a <see cref="IEntityField2"/> in the persistent storage.</returns>
        public string GetPersistentFieldName(IEntityField2 field)
        {
            var i = GetFieldPersistenceInfo(field);

            return(i.SourceColumnName);
        }