0

Currently I'm trying to combine two database tabels with a join enter image description here

After that I looping through the reader and create an Appointment Object foreach row that returned from the query. That Appointment object is added to a list.

enter image description here

The problem is when I start my program. The user data is not binded to the Customer object. Customer is still null here, but the customer data is added with the join.

enter image description here

How can I fix this issue? So that the Customer data that comes from the join is added to that Customer Model object.

3
  • 3
    Soo.. where's the bit of your code that looks like appointments.Add(new Appointment { ... Customer = new Customer( CustomerId = int.Parse( reader["CustomerId"])) ? Commented Mar 19, 2022 at 19:20
  • 1
    Please do not post images of code or data, paste them in as text. Please use images ony for things that cannot be shown as text Commented Mar 19, 2022 at 20:55
  • Side point: you need using blocks for your connection, command and reader objects Commented Mar 19, 2022 at 20:55

1 Answer 1

0

Looking at your screenshots, I can't see explicit binding for cutomer-related fields. And to understand the logic well, the list of appointments should have some sort of Customer object that u need to initialize while looping the reader.

appointments.add(new Appointment{
  Customer = new Customer{
    customerId = reader["Customers.CustomerId"]
    .
    .
    .
  },
  AppointmentId = reader["AppointmentId"],
  .
  .
  .
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.