public override string Create(IRecord record, IEnumerable <string> fieldsToSet) { var updateFields = GetCreateOrUpdateFields(record, fieldsToSet); var sql = SqlProvider.GetInsertString(record.Type, updateFields, false); ExecuteSql(sql); return(null); }
public string Create(IRecord record, IEnumerable <string> fieldsToSet, SqlProvider sqlService, SqlTransaction transaction) { var updateFields = GetCreateOrUpdateFields(record, fieldsToSet); var sql = SqlProvider.GetInsertString(record.Type, updateFields, true); var idRow = ExecuteSelect(sql, sqlService, transaction); if (!idRow.Any()) { throw new NullReferenceException("Cannot determine id no identity row was returned"); } var id = idRow.First().GetFieldAsString("ID"); return(id); }
public string Create(IRecord record, IEnumerable <string> fieldsToSet, SqlProvider sqlService, SqlTransaction transaction) { var updateFields = GetCreateOrUpdateFields(record, fieldsToSet); var hasPrimaryKey = !string.IsNullOrWhiteSpace(this.GetPrimaryKey(record.Type)); var sql = SqlProvider.GetInsertString(record.Type, updateFields, hasPrimaryKey); if (hasPrimaryKey) { var idRow = ExecuteSelect(sql, sqlService, transaction); if (hasPrimaryKey && !idRow.Any()) { throw new NullReferenceException("Cannot determine id no identity row was returned"); } var id = idRow.First().GetFieldAsString("ID"); return(id); } else { ExecuteSql(sql); return(null); } }