Exemplo n.º 1
0
        public void AddUpdate(ClrClass @class, DbTable table)
        {
            if (@class == null)
            {
                throw new ArgumentNullException("class");
            }
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }

            var varName = NameProvider.ToParameterName(@class.Name);

            _buffer.AppendLine(string.Format(@"public void Update({0} {1})", @class.Name, varName));

            this.BeginBlock();

            _buffer.AppendLine(this.GetParameterCheck(varName));
            this.AddEmptyLine();

            _buffer.AppendLine(string.Format(@"var query = @""{0}"";", QueryCreator.GetUpdate(table).Statement));
            this.AddEmptyLine();
            _buffer.AppendLine(@"var sqlParams = new []");

            this.BeginBlock();
            var index      = 0;
            var parameters = QueryCreator.GetParameters(table.Columns);

            foreach (var property in @class.Properties)
            {
                var type = property.Type;
                if (type.IsCollection)
                {
                    continue;
                }

                var name = property.Name;
                if (!type.IsBuiltIn)
                {
                    name += @"." + NameProvider.IdName;
                }
                _buffer.AppendLine(string.Format(@"QueryHelper.Parameter(@""{0}"", {1}.{2}),", parameters[index++].Name, varName, name));
            }
            this.EndBlockWith();

            this.AddEmptyLine();

            _buffer.AppendLine(@"QueryHelper.ExecuteQuery(query, sqlParams);");

            this.EndBlock();
        }