Hi
I have a question regarding how to create models with linked data and retrieve them correctly to avoid encountering NullReferenceException errors. Could you please share best practices or examples on setting up and accessing related data in a safe manner?
new ParseClient(new ServerConnectionData
{
ApplicationID = "",
ServerURI = "",
Key = "",
}).Publicize();
ParseClient.Instance.RegisterSubclass(typeof(EventType));
ParseClient.Instance.RegisterSubclass(typeof(Event));
[ParseClassName("Event")]
public class Event : ParseObject
{
public Event()
{
}
[ParseFieldName("title")]
public string Title
{
get => GetProperty<string>(null, nameof(Title));
set => SetProperty(value, nameof(Title));
}
[ParseFieldName("description")]
public string Description
{
get => GetProperty<string>(null, nameof(Description));
set => SetProperty(value, nameof(Description));
}
[ParseFieldName("eventType")]
public ParseObject EventType
{
get => GetProperty<EventType>(null, nameof(EventType));
set => SetProperty(value, nameof(EventType));
}
}
[ParseClassName("EventType")]
public class EventType : ParseObject
{
public EventType()
{
}
[ParseFieldName("name")]
public string Name
{
get => GetProperty<string>(null, nameof(Name));
set => SetProperty(value, nameof(Name));
}
}
var events = await ParseClient.Instance
.GetQuery<Event>()
.GetAsync("vGL4v8VYsE");
//NullReferenceException errors
ParseQuery<ParseObject> query = ParseClient.Instance.GetQuery("Event");
var result = await query.GetAsync("vGL4v8VYsE");
//NullReferenceException errors
Data in the database
{
"results": [
{
"title": "Test 6",
"description": "New descriptions",
"eventType": {
"name": "Бег",
"createdAt": "2025-04-07T17:50:47.703Z",
"updatedAt": "2025-04-08T14:49:58.292Z",
"objectId": "xqDSKujsM7",
"__type": "Object",
"className": "EventType"
},
"objectId": "vGL4v8VYsE"
}
]
}
Thank you.