How do you take a SQlite result and insert it into Model Values so they can be reused?

How do you take a SQlite result and insert it into Model Values so they can be reused?

Problem Description:

Details in the title, code is below. How do I populate the model values from the SQlite response?

//Current line returns the below response
var test2 = await Database.QueryAsync<User>("SELECT * FROM User");

Return result

Model

    public class User
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Username { get; set; }
        public string Token { get; set; }
    }

Solution – 1

SQLite.NET will return a list of User objects, you don’t need to do anything to populate them

var query = await Database.Table<User>();
var results = await query.ToListAsync();

foreach (var user in results)
{
   // user is a User object
}
Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Reject