Exemple #1
0
        public void UpdateObject(DMSource DataObject)
        {
            UpdateQuery query = QueryBuilder.Update(TABLE);

            ((UpdateQuery)query).AddWhereFragment(DataObject.ID);

            foreach (var entry in DATA_MAP.DataColumns)
            {
                var value = entry.Value.GetValue(DataObject);
                if (value != null)
                {
                    query.AddPropertyValue(entry.Key.ColumnName, @value.ToString().Replace("'", "''''"));
                }
            }

            var cmd = db.GetCommand(query.Build());

            cmd.ExecuteNonQuery();
        }
Exemple #2
0
        public void TestGenerateUpdateWithID()
        {
            var         schemeName    = TestingTools.RandomString;
            var         tableName     = TestingTools.RandomString;
            var         propertyName  = TestingTools.RandomString;
            var         propertyValue = TestingTools.RandomString;
            var         id            = TestingTools.RandomInt;
            UpdateQuery query         = new UpdateQuery(schemeName, tableName);

            query.AddPropertyValue(propertyName, propertyValue);
            query.AddWhereFragment(id);

            var result = query.Build();

            var expected = String.Format("UPDATE \"{0}\".\"{1}\" SET \"{2}\"='{3}' WHERE \"ID\"={4};",
                                         schemeName, tableName, propertyName, propertyValue, id);

            Assert.IsNotNull(result);
            Assert.AreEqual(expected, result);
        }
Exemple #3
0
        public void TestGenerateUpdateWithWhere()
        {
            var         schemeName    = TestingTools.RandomString;
            var         tableName     = TestingTools.RandomString;
            var         propertyName  = TestingTools.RandomString;
            var         propertyValue = TestingTools.RandomString;
            var         id            = TestingTools.RandomInt;
            UpdateQuery query         = new UpdateQuery(schemeName, tableName);

            query.AddPropertyValue(propertyName, propertyValue);
            Expression <Func <ConnectionDM, bool> > exp = (item) => item.ChildID == id;

            query.AddWhereFragment((BinaryExpression)exp.Body);

            var result = query.Build();

            var expected = String.Format("UPDATE \"{0}\".\"{1}\" SET \"{2}\"='{3}' WHERE \"ChildID\" = '{4}';",
                                         schemeName, tableName, propertyName, propertyValue, id);

            Assert.IsNotNull(result);
            Assert.AreEqual(expected, result);
        }