Example #1
0
        public int CountOfRecordsWithPrimaryKey(IDictionary<string, string> record)
        {
            var parameters = record.AsDynamicParameters();

            var checkIfExists = string.Format("SELECT COUNT(1) FROM {0} WHERE {1}", this.TableName, this.PrimaryKeyLocator);

            return this.connection.Query<int>(checkIfExists, parameters).Single();
        }
Example #2
0
        public void InsertRecord( IDictionary<string, string> record)
        {
            var columns = string.Join(", ", record.Keys);
            var values = string.Join(", ", record.Keys.Select(x => "@" + x));

            var insert = string.Format("BEGIN TRY SET IDENTITY_INSERT {0} ON END TRY BEGIN CATCH END CATCH; INSERT INTO {0}({1}) VALUES({2})", this.TableName, columns, values);

            this.connection.Query<int>(insert, record.AsDynamicParameters());
        }
Example #3
0
        public void UpdateRecord(IDictionary<string, string> record)
        {
            var set = string.Join(", ", record.Keys.Except(this.PrimaryKeyColumns).Select(x => x + " = @" + x));

            var update = string.Format("UPDATE {0} SET {1} WHERE {2}", this.TableName, set, this.PrimaryKeyLocator);

            this.connection.Query<int>(update, record.AsDynamicParameters());
        }