Here is the class to which I convert the document data:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Google.Cloud.Firestore;
namespace FYP_Desktop
{
[FirestoreData]
public class InitialPayment
{
[FirestoreProperty]
public string PurchaseOrder { get; set; }
[FirestoreProperty]
public string PurchaseAmount { get; set; }
[FirestoreProperty]
public string PackingDepartment { get; set; }
[FirestoreProperty]
public string CustomerStatus { get; set; }
[FirestoreProperty]
public string PaymentPercentile { get; set; }
}
}
The problem I am having is that I get empty rows on the UI even though the firebase collection contains the documents.
Here is the snippet where I try to bind the incoming data with datagridview:
CollectionReference coll = conn.db.Collection("payments");
FirestoreChangeListener listener = coll.Listen(
snapshot =>
{
// this clear function clears the data grid view
// by this, we are able to eliminate the duplicate data binding in the data grid view
dgvPayments.Rows.Clear();
foreach (DocumentSnapshot docs in snapshot.Documents)
{
InitialPayment payment = docs.ConvertTo<InitialPayment>();
dgvPayments.Rows.Add(payment.PurchaseOrder, payment.PurchaseAmount, payment.PackingDepartment,
payment.CustomerStatus, payment.PaymentPercentile);
}
}
);
Debugging the snippet using a breakpoint also shows that values are null even though I have documents in the collection in Firebase:
CodePudding user response:
After a few more efforts, I was able to resolve the issue by making the document field names and InitialPayment's property names identical. Doing so fetched the data properly.