Realtime database .Net Objects in Backendless

Hi Backendless Team.

I have a problem with my WPF Application .Net. I can’t seem to retrieve content that is saved in my Backendless table (e.g. Diary) and save it in my custom class list (e.g. List)…could you please assist

Your Assistance will be highly appreciated.

Hi @Onalerona_Gabanakgosi,

could you please describe how you performing data retrieving?
What do you mean by saying “can’t seem to retrieve” - do you get any error or maybe just an empty array?

Regards
Stanislaw

Hi @stanislaw.grin

Thanks for getting back to me.

I don’t know if its the way I’m retrieving the data.
I did the following:
public partial class Home : Page
{

    public Home()
    {
        InitializeComponent();
        Backendless.InitApp("10E7E62D-DE02-F693-FF82-5BD03AA18200", "D5763994-CB98-4D90-9F55-1A1A26B174D8");
        GetDiary();
    }

    private async void GetDiary()
    {
        try
        {
            List<Diary> diaryEntries = new List<Diary>();
            var entries = await Backendless.Data.Of("Diary").FindAsync();

            foreach (var entry in entries)
            {
                diaryEntries.Add(entry); (I get an error here)
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
        
    }
}

What error do you get?

Hi @stanislaw.grin

Error CS1503 Argument 1: cannot convert from ‘object’ to ‘DiaryOfTheCEO.Diary’ (Diary is my Custom Class)

  1. Error CS1503 Argument 1: cannot convert from ‘System.Collections.Generic.Dictionary<string, object>’ to ‘DiaryOfTheCEO.Diary’ DiaryOfTheCEO

I need your assistance with adding the objects saved in my backendless Table to my List in my WPF application of Type Diary(Which is the same as my Table name)

Have you tried Custom Class approach from this doc?
https://backendless.com/docs/dotnet/data_basic_search.html

public void Backendless.Data.Of<Diary>().Find( AsyncCallback<IList<Diary>> callback );

Also “class to table mapping” approach may help you too:
https://backendless.com/docs/dotnet/data_class_to_table_mapping.html

Hi @stanislaw.grin
could you please show me an example of how you use that Custom Class Approacj, because on my end it gives me an error

I have a Data grid named dtGridDiary, so I need to populate it with contents of my Table in Backendless. Example: If I had List of type Diary(List listDiary = new List():wink: that has 5 objects, then I would do the following-

if (listDiary.Count > 0)
{
foreach (Diary diary in listDiary)
{
dtGridDiary.Items.Add(diary);
}
}

how do I use This approach : public void Backendless.Data.Of().Find( AsyncCallback<IList> callback );?

Could you please show what the Diary class looks like in your code?

Hi @mark-piller

Thanks for getting back to me, I appreciate your efforts.

it looks like this:

class Diary
{
public int EntryNr
{ get; set; }
public string DateEntry
{ get; set;}

    public string Details
    { get; set;}       
    
    public string Subject
    { get; set;}

}

my Table in Backendless is named Diary and the columns are the same as the attributes of the Class

Please make sure to declare the class as public. Let me know if this doesn’t solve the issue.

I did all that…I just need an example of how to use this: public void Backendless.Data.Of().Find( AsyncCallback callback );

Do I make it a method or do I assign it to a variable before I display it to my Data Grid?

This Approach public void Backendless.Data.Of().Find( AsyncCallback<IList> callback );

There are plenty of examples you can find here:
https://backendless.com/docs/dotnet/data_search_with_where_clause.html

Do you want it with a class or with a collection of Dictionary objects?

With a custom class, because the Data Grid that displays information needs a Custom Class

Here’s the example in the docs:

Hi @mark-piller

I get this error: Severity Code Description Project File Line Suppression State
Error CS0426 The type name ‘Create’ does not exist in the type ‘DataQueryBuilder’

By this line: DataQueryBuilder queryBuilder = new DataQueryBuilder.Create();

That’s a typo in the docs. Remove new, since it is not a constuctor.

Hi @mark-piller

Can I please get assistance on how do I access the information in the table after I do this:

AsyncCallback<IList> findCallback;
findCallback = new AsyncCallback<IList>(
foundObjects =>
{
System.Console.WriteLine( “Server returned " + foundObjects.Count + " objects” );
},
error =>
{
System.Console.WriteLine( "Server returned an error " + error.Message );
} );

Backendless.Data.Of().Find( queryBuilder, findCallback );