Exemple #1
0
        public T2 Max <T2>(Expression <Func <T, T2> > expression)
        {
            string        prop   = ExpressionHelper.GetExpressionMemberName(expression);
            ColumnMapping column = TableMapping.GetColumnMappingByProperty(prop);

            return((T2)base.Max(column != null ? column.Name : prop));
        }
        public Criteria <T> AddConditionPropertyValues(SqlConditionType type, string prop, IList vals)
        {
            ColumnMapping column = TableMapping.GetColumnMappingByProperty(prop);

            this.AddConditionColumnValues(type, column != null ? column.Name : prop, vals);
            return(this);
        }
Exemple #3
0
        public Criteria <T> AddUpdateProperty(Expression <Func <T, object> > expression, object val)
        {
            string        prop   = ExpressionHelper.GetExpressionMemberName(expression);
            ColumnMapping column = TableMapping.GetColumnMappingByProperty(prop);

            this.UpdateParameters.Add(new SqlParameter(column != null ? column.Name : prop, val));
            return(this);
        }
Exemple #4
0
        public Criteria <T> AddOrderProperty(Expression <Func <T, object> > expression, SqlOrderType type = SqlOrderType.ASC)
        {
            string        prop   = ExpressionHelper.GetExpressionMemberName(expression);
            ColumnMapping column = TableMapping.GetColumnMappingByProperty(prop);

            base.AddOrderColumn(column != null ? column.Name : prop, type);
            return(this);
        }
Exemple #5
0
        public Criteria <T> AddProperty(Expression <Func <T, object> > expr)
        {
            var memberExpression = expr.Body as MemberExpression;

            if (memberExpression == null)
            {
                AnonymousObjectPropertiesExpressionVisitor Visitor = new AnonymousObjectPropertiesExpressionVisitor();
                Visitor.Visit(expr);
                foreach (var prop in Visitor.Properties)
                {
                    ColumnMapping column = TableMapping.GetColumnMappingByProperty(prop);
                    base.AddColumn(column != null ? column.Name : prop);
                }
            }
            else
            {
                string        prop   = memberExpression.Member.Name;
                ColumnMapping column = TableMapping.GetColumnMappingByProperty(prop);
                base.AddColumn(column != null ? column.Name : prop);
            }
            return(this);
        }
Exemple #6
0
        public int Update(Expression <Func <object> > expression)
        {
            HashSet <string> props = ExpressionHelper.GetExpression_PropertyList(expression);

            if (props.Count == 0)
            {
                throw new ObjectMappingException("not any property updated!");
            }

            object obj     = expression.Compile()();
            Type   objType = obj.GetType();

            foreach (var prop in props)
            {
                var           val    = objType.GetProperty(prop).GetValue(obj, null);
                ColumnMapping column = TableMapping.GetColumnMappingByProperty(prop);
                this.UpdateParameters.Add(new SqlParameter(column != null ? column.Name : prop, val));
            }

            DatabaseEngine db = DatabaseEngineFactory.GetDatabaseEngine();

            return(db.Update(this));
        }
        public virtual int Update(TableMapping table, object obj, HashSet <string> updateprops)
        {
            Criteria criteria = new Criteria(table);

            criteria.AddEqualTo(table.ColumnPK.Name, table.ColumnPK.GetValue(obj));
            if ((updateprops != null) && (updateprops.Count > 0))
            {
                foreach (string propname in updateprops)
                {
                    ColumnMapping column = table.GetColumnMappingByProperty(propname);
                    if (column == null)
                    {
                        continue;
                    }

                    if ((column.IsPK == false) && (column.IsAutoIncrement == false))
                    {
                        criteria.AddUpdateColumn(column.Name, column.GetValue(obj));
                    }
                    else
                    {
                        throw new ObjectMappingException(propname);
                    }
                }
            }
            else
            {
                foreach (ColumnMapping column in table.Columns)
                {
                    if ((column.IsPK == false) && (column.IsAutoIncrement == false))
                    {
                        criteria.AddUpdateColumn(column.Name, column.GetValue(obj));
                    }
                }
            };
            return(this.Update(criteria));
        }