I am developing a project using MongoDB realm. But get stuck in the beginning of the project. I am adding a model to the Realm Database. But due to some reason it does not work. The code where I am adding the model is as follows:
public MilkManProfile MilkManProfile { get; set; }
realm = Realm.GetInstance();
MilkManProfile = realm.All<MilkManProfile>().FirstOrDefault();
public async Task Login()
{
bool isCodeValid = await ValidateVerificationCode();
if (isCodeValid)
{
realm.Write(()=>
{
realm.Add(MilkManProfile);
});
await AppShell.Current.GoToAsync("milkManProfile");
}
}
But the Model is not being added. The Model class is:
public class MilkManProfile : RealmObject
{
[PrimaryKey]
[MapTo("_id")]
public ObjectId UserId { get; set; } = ObjectId.GenerateNewId();
public string Name { get; set; }
public DateTimeOffset DateOfBirth { get; set; }
public string Sex { get; set; }
public string Locality { get; set; }
public string Pin { get; set; }
public string PostOffice { get; set; }
public string District { get; set; }
public string City { get; set; }
public string State { get; set; }
public string PhoneNumber { get; set; }
}
When I try to access the MilkManProfile in another ViewModel it returns null. Here is the link to the Project