【发布时间】:2018-02-20 18:41:14
【问题描述】:
我必须用 SQlite 表中的一列填充 ComboBox
我使用它来选择 Column 但我认为查询应该是字符串列表,我如何将(对象)转换为字符串列表?
public List<string> SystemsNameList()
{
using (SQLiteConnection conn = new SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), App.DB_PATH))
{
var SystemsName = conn.Query<FFSystems>("select Name from FFSystems");
return SystemsName;
}
}
这是保存在数据库表中的对象的定义
public class FFSystems
{
[PrimaryKey][AutoIncrement]
public int ID { get; set; }
public string Name { get; set; }
public int IDCode { get; set; }
public bool Active { get; set; }
public string CreationDate { get; set; }
public FFSystems() { }
public FFSystems(string name, int idcode, bool active)
{
Name = name;
IDCode = idcode;
Active = active;
CreationDate = DateTime.Now.ToString();
}
}
【问题讨论】:
-
SystemsNames.Cast<string>().ToList()工作吗? -
不,我在使用时遇到了 InvalidCastExcepion
-
SystemsName 是什么类型?
-
SystemsName 是表中的一个对象,但我在查询中只选择了一列字符串。
-
试试
return SystemsName.Select(n => n.Name).ToList();