Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    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 :

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
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading