简体   繁体   中英

How can I get the table names from the following query in sqlite c#

this is only returning the below, how can I capture the names of the tables in the DB

var tables = database.Query(map, "SELECT name FROM sqlite_master WHERE type = 'table'", ps);

在此处输入图像描述

It seems you are having problems with the Mappings.

Another way you could get the table names is as follow:

Create a class with the following structure:

[Table("sqlite_master")]
public class SqliteMaster
{
    public SqliteMaster()
    {

    }

    [Column("type")]
    public string Type { get; set; }

    [Column("name")]
    public string Name { get; set; }

    [Column("tbl_name")]
    public string TableName { get; set; }
}

And then you can use the Sqlite Table method + Linq to extract the data.

Something like this:

var names = db.Table<SqliteMaster>()
              .Where(a => a.Type == "table")
              .Select(a => a.Name)
              .ToList();

This should give you what you are looking for.

Hope this helps.-

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM