Пример #1
0
        public AssignListBuilder BuildForObject(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            if (this.tables.Any() == false)
            {
                throw new InvalidOperationException("At least one table must be specified");
            }

            var typeOfObject       = obj.GetType();
            var propertiesOfObject = typeOfObject.GetProperties().Where(p => p.CanRead).ToArray();

            foreach (var table in this.tables)
            {
                var tp = this.GetTableProperties(table);
                foreach (var po in propertiesOfObject)
                {
                    var tcol = tp.SingleOrDefault(p => p.Name == po.Name);
                    if (tcol != null)
                    {
                        Expression constantExpr;
                        if (Expression.TryGetConstant(po.GetValue(obj), out constantExpr))
                        {
                            var ea = new ExpressionAssign((Column)tcol.GetValue(table), constantExpr);
                            this.Append(ea);
                        }
                    }
                }
            }
            return(this);
        }
Пример #2
0
 public void VisitExpressionAssign(SqlFragment parent, ExpressionAssign expressionAssign)
 {
     expressionAssign.Column.Build(expressionAssign, this);
     this.Script.Append("=");
     expressionAssign.Expression.Build(expressionAssign, this);
 }
Пример #3
0
        public AssignListBuilder BuildForObject(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            if (this.tables.Any() == false)
            {
                throw new InvalidOperationException("At least one table must be specified");
            }

            var typeOfObject = obj.GetType();
            var propertiesOfObject = typeOfObject.GetProperties().Where(p => p.CanRead).ToArray();
            foreach (var table in this.tables)
            {
                var tp = this.GetTableProperties(table);
                foreach (var po in propertiesOfObject)
                {
                    var tcol = tp.SingleOrDefault(p => p.Name == po.Name);
                    if (tcol != null)
                    {
                        Expression constantExpr;
                        if (Expression.TryGetConstant(po.GetValue(obj), out constantExpr))
                        {
                            var ea = new ExpressionAssign((Column)tcol.GetValue(table), constantExpr);
                            this.Append(ea);
                        }
                    }
                }
            }
            return this;
        }