5

given below is the method I used to retrieve details from a Dynamodb table. But when I call this method it ended up throwing an exception "Unable to locate property for key attribute appointmentId". primary key of this particular table is appointmentId, but I've already created a global secondary index on patientId column. I'm using that index in below query to get the appointment details by a given patientID.

public async Task GetAppointmentByPatientID(int patientID)
        {
            var context = CommonUtils.Instance.DynamoDBContext;


            PatientAppointmentObjectList.Clear();


            DynamoDBOperationConfig config = new DynamoDBOperationConfig();
            config.IndexName = DBConstants.APPOINTMENT_PATIENTID_GSI;
            AsyncSearch<ScheduledAppointment> appQuery = context.QueryAsync<ScheduledAppointment>(patientID.ToString(), config);
            IEnumerable<ScheduledAppointment> appList = await appQuery.GetRemainingAsync();

            appList.Distinct().ToList().ForEach(i => PatientAppointmentObjectList.Add(i));

            if (PropertyChanged != null)
                this.OnPropertyChanged("PatientAppointmentObjectList");
        }
    }
Asanga Dewaguru
  • 1,058
  • 2
  • 16
  • 31
  • what is the index name in your query? Do you create an extra index or it is simply the name of your database? – Emil Dec 17 '16 at 15:44
  • I had your problem and it was driving me mad. My DynamoDBHashKey didn't exist but the message said "Id" and that wasn' t the right column name – Rob Sedgwick Apr 26 '23 at 14:00

1 Answers1

10

It was a silly mistake. I've had the hash key column of the table as "appointmentID" and the model object property named as AppointmentID. mismatch in the case of the property name had confused the dynamodb mapping.

Asanga Dewaguru
  • 1,058
  • 2
  • 16
  • 31
  • 3
    The casing of property names must match exactly for the Dynamo client to work right. They ought to put that in big bold letters at the top of the documentation. – Jordan Wilcken May 04 '18 at 15:53
  • Wanted to add that, if you require to have specific naming on DynamoDB however want to use different casing like pascal case as we usually do for properties you can do use the `[DynamoDBProperty("year")], [DynamoDBHashKey("title")]` etc above your property named Year, Title etc. – tkauran Jul 18 '21 at 20:34