I have a c# appliction which is deal with firebase data base on order to get data from it for specific item, An object reference is required for the non-static field, method, or property
return this error in AppintmentService.GetFollowUp(patient.ID)
line,
what is the mistake i did ?
public ICommand Appearing { get => _Appearing; set => SetProperty(ref _Appearing, value, nameof(Appearing)); }
public PatientProfileFollowUpPageModelView(Patient patient)
{
Appearing = new AsyncCommand(async () => await LoadData(patient));
}
The function :
async Task LoadData(Patient patient)
{
Appoitments = new ObservableCollection<Appoitment>(await AppintmentService.GetFollowUp(patient.ID));
}
and the service :
public ObservableCollection<Appoitment> GetFollowUp(string PatientID)
{
var FollowUp = firebaseClient
.Child($"Specalists/{PreferencesConfig.Id}/Patients/{PatientID}/Appointments")
.AsObservable<Appoitment>()
.AsObservableCollection();
return FollowUp;
}
CodePudding user response:
GetFollowUp
is a method on the class AppintmentService
, so you need an instance of AppintmentService
in order to call it.
var svc = new AppintmentService);
var result = svc.GetFollowUp(patient.ID)
alternately, you can make GetFollowUp
a static method, which would allow you to call it without having an instance
in either case, GetFollowUp
is not marked async, so calling it using await
is not neccessary