我创建了一个带有sqlite连接的xamarin应用。当我运行此代码时,它会导致异常:
public List<string> GetTpe(string word)
{
return dbConnection.Query<string>("Select * From Entries Where Entries.word =?", word).ToList();
}
这是我的课程条目:
public class Entries
{
public Entries()
{
}
public Entries(string word)
{
this.word = word;
}
public Entries(string word, string wordtype, string definition)
{
this.word = word;
this.type = wordtype;
this.defn = definition;
}
public string word
{ get; set; }
public string type
{ get; set; }
public string sdex { get; set; }
public int wlen { get; set; }
public string defn
{ get; set; }
//public List<string> Word { get; set; }
}
这是例外:System.MissingMethodException:找不到类型为'System.String'的构造方法。
请帮助。非常感谢。
答案 0 :(得分:0)
此SQL查询返回Entries
个对象,而不是string
。
Query<string>("Select * From Entries Where Entries.word = ?", word)
如果您尝试仅返回string
的列表,而string
是记录中的一个字段,请将该字段分解为各个部分:
var entriesList = conn.Query<Entries>("Select * From Entries Where Entries.word =?", word);
var stringEnumuerationOfDefn = entriesList.Select(entries => entries.defn);
var stringListOfDefn = stringEnumuerationOfDefn.ToList();
更新:
conn.Insert(new Entries { word = "someWord", defn = "defn1", sdex = "sdex1" });
string wordFilter = "someWord";
var entriesList = conn.Query<Entries>("Select * From Entries Where Entries.word = ? ", word); // new string[1] { word });
var wordEnumueration = entriesList.Select(entries => entries.defn);
var wordList = wordEnumueration.ToList();
foreach (var word in wordList)
{
Console.WriteLine(word)
}