I need to get invoices for a contact by contact Id, therefore I wrote Query 1 similar to Qusery 3 (which is working for payments). My objective is to query invoices from a field belongs to it's associated object Contact. But Query 1 returns 0 results.
Then I tried the way I querying for invoices, to query by a field belongs to Invoices. I was referring to the Xero C# code samples in GitHub. It's working and returns 10 results as expected.
Why can't I query from a ContactId field belongs to contact in an invoice?
Code
QUERY 1 (NOT WORKING - Return 0 results, expecting 10 results)
var contact = _api.Contacts.Find().FirstOrDefault(c => c.AccountNumber == accountNumber);
returnInvoiceList =
_api.Invoices.Find()
.Where(c => c.Contact.Id == contact.Id)
.OrderBy(item => typeof(Invoice).GetProperty(
orderby, BindingFlags.Public | BindingFlags.Instance).GetValue(item))
.Skip(i * x)
.Take(x)
.ToList();
QUERY 2 (WORKING)
returnInvoiceList =
_api.Invoices.Where(string.Format("Reference == \"{0}\"", accountNumber)).Find()
.OrderBy(item => typeof(Invoice).GetProperty(
orderby, BindingFlags.Public | BindingFlags.Instance).GetValue(item))
.Skip(i * x)
.Take(x)
.ToList();
QUERY 3 (Similar pattern query to Query 1, working for payments)
returnPaymentList =
_api.Payments.Find()
.Where(c => c.Invoice.Contact.Id == contact.Id)
.OrderBy(item => typeof(Payment).GetProperty(
orderby, BindingFlags.Public | BindingFlags.Instance).GetValue(item))
.Skip(i * x)
.Take(x)
.ToList();