问题描述
我正在尝试对本地SQLite数据库使用Linq查询来分配Picker ItemsSource属性。但是,我得到的是“ {{Page_Title = Test 1}” 而不是Test 1。 其中:
Page_Title是SQLite表中的列名
测试1是我想要返回的值
我假设得到的原因是因为我使用列表而不是字符串。但是,当我尝试使用列表时,出现以下错误:
CS0029:无法将类型“ System.Collections.Generic.List匿名类型:字符串Page_Title”隐式转换为“ System.Collections.Generic.List字符串”
我尝试使用.ConvertAll转换字符串,但确实删除了 {Page_Title =} 仅返回测试1,但它作为每个字符作为列表中的一项返回。如下:
“ T”
“ e”
“ s”
“ t”
“ 1”
带有对象的代码
VM_AnalyzePage CurrentPage = new VM_AnalyzePage();
var pageList = (from UserPageTbl in conn.Table<UserPageTbl>()
where UserPageTbl.User_ID == App.user
select new
{
UserPageTbl.Page_Title
}).Distinct().OrderBy(Page_Title => Page_Title).ToList<object>();
CurrentPage.PageList = pageList;
带字符串的代码
var pageList = (from UserPageTbl in conn.Table<UserPageTbl>()
where UserPageTbl.User_ID == App.user
select new
{
UserPageTbl.Page_Title
}).Distinct().OrderBy(Page_Title => Page_Title).ToList();
CurrentPage.PageList = pageList;
这是我要设置其值的类。注意,当我尝试转换为字符串时,在下面将“ object”更改为“ string”:
public class VM_AnalyzePage : INotifyPropertyChanged
{
//properties
private List<object> pageList;
public List<object> PageList
{
get
{
return pageList;
}
set
{
pageList = value;
}
}
我还尝试过在下面投射“ pageList”变量以键入List字符串,但是随后出现相同的错误:
List<string> pageList = (from UserPageTbl in conn.Table<UserPageTbl>()
where UserPageTbl.User_ID == App.user
select new
{
UserPageTbl.Page_Title
}).Distinct().OrderBy(Page_Title => Page_Title).ToList();
CurrentPage.PageList = pageList;
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)