Exemple #1
0
        public void Merge(PacketData entity, string[] keys)
        {
            // UPDATE
            Dictionary <string, string> commandNames = new Dictionary <string, string>();
            Dictionary <string, object> commands     = new Dictionary <string, object>();

            string query = "UPDATE " + entity.Definition.Name + " SET ";

            int count = 0;

            for (int i = 0; i < entity.Definition.Items.Length; i++)
            {
                query += entity.Definition.Items[i].Name + "=" + "@" + count.ToString();
                commands.Add("@" + count.ToString(), entity.Get(entity.Definition.Items[i].Name));
                commandNames.Add(entity.Definition.Items[i].Name, "@" + count.ToString());

                if ((i + 1) < (entity.Definition.Items.Length))
                {
                    query += ", ";
                }

                count++;
            }

            query += " WHERE ";

            for (int i = 0; i < keys.Length; i++)
            {
                string key = keys[i];

                query += key + "=" + commandNames[key];

                if ((i + 1) < (keys.Length))
                {
                    query += " AND ";
                }
            }

            customRepository.ExecuteQuery(query, commands);
        }