コード例 #1
0
        /// <summary> Gets a scalar value, calculated with the aggregate and expression specified. the field index specified is the field the expression and aggregate are applied on.</summary>
        /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param>
        /// <param name="expressionToExecute">The expression to execute. Can be null</param>
        /// <param name="aggregateToApply">Aggregate function to apply. </param>
        /// <param name="filter">The filter to apply to retrieve the scalar</param>
        /// <param name="relations">The relations to walk</param>
        /// <param name="groupByClause">The groupby clause to apply to retrieve the scalar</param>
        /// <returns>the scalar value requested</returns>
        public virtual object GetScalar(SupplierFieldIndex fieldIndex, IExpression expressionToExecute, AggregateFunction aggregateToApply, IPredicate filter, IRelationCollection relations, IGroupByCollection groupByClause)
        {
            EntityFields fields = new EntityFields(1);

            fields[0] = EntityFieldFactory.Create(fieldIndex);
            if ((fields[0].ExpressionToApply == null) || (expressionToExecute != null))
            {
                fields[0].ExpressionToApply = expressionToExecute;
            }
            if ((fields[0].AggregateFunctionToApply == AggregateFunction.None) || (aggregateToApply != AggregateFunction.None))
            {
                fields[0].AggregateFunctionToApply = aggregateToApply;
            }
            return(DAOFactory.CreateSupplierDAO().GetScalar(fields, this.Transaction, filter, relations, groupByClause));
        }
コード例 #2
0
        public static string ToJson(this EntityBase entity, Formatting formatting,
                                    params JsonConverter[] converters)
        {
            EntityFields ef   = EntityFieldsCache.Item(entity.GetType());
            JObject      json = new JObject();

            for (var i = 0; i < entity.PropertyNames.Length; i++)
            {
                var name  = entity.PropertyNames[i];
                var value = entity.PropertyValues[i];

                json.Add(new JProperty(ef.GetPropertyName(name), value));
            }

            return(json.ToString(formatting, converters));
        }
コード例 #3
0
        /// <summary> Gets a scalar value, calculated with the aggregate and expression specified. the field index specified is the field the expression and aggregate are applied on.</summary>
        /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param>
        /// <param name="expressionToExecute">The expression to execute. Can be null</param>
        /// <param name="aggregateToApply">Aggregate function to apply. </param>
        /// <param name="filter">The filter to apply to retrieve the scalar</param>
        /// <param name="relations">The relations to walk</param>
        /// <param name="groupByClause">The groupby clause to apply to retrieve the scalar</param>
        /// <returns>the scalar value requested</returns>
        public virtual object GetScalar(RecycleServiceActionFieldIndex fieldIndex, IExpression expressionToExecute, AggregateFunction aggregateToApply, IPredicate filter, IRelationCollection relations, IGroupByCollection groupByClause)
        {
            EntityFields fields = new EntityFields(1);

            fields[0] = EntityFieldFactory.Create(fieldIndex);
            if ((fields[0].ExpressionToApply == null) || (expressionToExecute != null))
            {
                fields[0].ExpressionToApply = expressionToExecute;
            }
            if ((fields[0].AggregateFunctionToApply == AggregateFunction.None) || (aggregateToApply != AggregateFunction.None))
            {
                fields[0].AggregateFunctionToApply = aggregateToApply;
            }
            RecycleServiceActionDAO dao = DAOFactory.CreateRecycleServiceActionDAO();

            return(dao.GetScalar(fields, base.Transaction, filter, relations, groupByClause));
        }
コード例 #4
0
        public static Func <T, T> DynamicSelectGenerator <T>(string Fields = "")
        {
            string[] EntityFields;
            if (Fields == "")
            {
                // get Properties of the T
                EntityFields = typeof(T).GetProperties().Select(propertyInfo => propertyInfo.Name).ToArray();
            }
            else
            {
                EntityFields = Fields.Split(',');
            }

            // input parameter "o"
            var xParameter = Expression.Parameter(typeof(T), "o");

            // new statement "new Data()"
            var xNew = Expression.New(typeof(T));

            // create initializers
            var bindings = EntityFields.Select(o => o.Trim())
                           .Select(o =>
            {
                // property "Field1"
                var mi = typeof(T).GetProperty(o);

                // original value "o.Field1"
                var xOriginal = Expression.Property(xParameter, mi);

                // set value "Field1 = o.Field1"
                return(Expression.Bind(mi, xOriginal));
            }
                                   );

            // initialization "new Data { Field1 = o.Field1, Field2 = o.Field2 }"
            var xInit = Expression.MemberInit(xNew, bindings);

            // expression "o => new Data { Field1 = o.Field1, Field2 = o.Field2 }"
            var lambda = Expression.Lambda <Func <T, T> >(xInit, xParameter);

            // compile to Func<Data, Data>
            return(lambda.Compile());
        }
コード例 #5
0
        /// <summary>
        /// 根据指定的实体类中的属性名,返回实体类的表名称和属性对应的字段名称
        /// </summary>
        /// <param name="fullClassName">实体类名称</param>
        /// <param name="propertyName">属性名称</param>
        /// <returns>返回实体类的表名称和属性对应的字段名称</returns>
        public string[] TableFieldName(string fullClassName, string propertyName)
        {
            ErrorMessage = "";
            Type objType = null;

            foreach (var t in assembly.GetTypes())
            {
                if (t.FullName == fullClassName || t.Name == fullClassName)
                {
                    objType = t;
                    break;
                }
            }
            if (objType != null)
            {
                EntityFields ef = new EntityFields();
                if (ef.InitEntity(objType))
                {
                    string fieldName = ef.GetPropertyField(propertyName);
                    if (fieldName == null)
                    {
                        this.ErrorMessage = "属性 " + propertyName + " 不是PDF.NET的实体类属性,无法找到对应的属性字段。";
                        return(null);
                    }
                    else
                    {
                        string[] arr = { ef.TableName, fieldName };
                        return(arr);
                    }
                }
                else
                {
                    this.ErrorMessage = "类型 " + fullClassName + " 不是PDF.NET实体类。";
                    return(null);
                }
            }
            ErrorMessage = "未找到类型 " + fullClassName;
            return(null);
        }
コード例 #6
0
        public static void FromJson(this EntityBase entity, string json)
        {
            EntityFields ef  = EntityFieldsCache.Item(entity.GetType());
            var          obj = JObject.Parse(json, null);

            foreach (var p in obj.Properties())
            {
                var name = ef.GetPropertyField(p.Name);
                if (!string.IsNullOrEmpty(name))
                {
                    string temp   = null;
                    int    length = name.Length;
                    for (int i = 0; i < entity.PropertyNames.Length; i++)
                    {
                        temp = entity.PropertyNames[i];
                        if (temp != null && temp.Length == length &&
                            string.Equals(temp, name, StringComparison.OrdinalIgnoreCase))
                        {
                            entity.PropertyValues[i] = p.Value.Value <object>();
                        }
                    }
                }
            }
        }
コード例 #7
0
 /// <summary>Creates a complete EntityFields instance for the QTreminderEntity.</summary>
 /// <returns></returns>
 private static IEntityFields CreateQTreminderTypedViewEntityFields()
 {
     IEntityFields fieldsToReturn = new EntityFields((int)QTreminderFieldIndex.AmountOfFields, null, FieldInfoProviderSingleton.GetInstance().GetFieldIndexes("QTreminderTypedView"));
     for(int i=0;i<(int)QTreminderFieldIndex.AmountOfFields;i++)
     {
         fieldsToReturn[i] = EntityFieldFactory.Create((QTreminderFieldIndex)i);
     }
     return fieldsToReturn;
 }
コード例 #8
0
        public string GetEntityFieldName(string dbFieldName)
        {
            var index = DbFields.FindIndex(f => String.Compare(f, dbFieldName, StringComparison.OrdinalIgnoreCase) == 0);

            return((index >= 0 && EntityFields.Count > index) ? EntityFields.ElementAt(index) : dbFieldName);
        }