使用Xamarin.Forms从Sqlite数据库获取数据

使用Xamarin.Forms从Sqlite数据库获取数据,sqlite,xamarin,xamarin.forms,xamarin.android,android-sqlite,Sqlite,Xamarin,Xamarin.forms,Xamarin.android,Android Sqlite,当我用Xamarin和sqlite创建一个应用程序时。我运行了一条语句,但它在emulator屏幕上显示了这句话:System.Linq.Enumerable+SelectEnumerableInterator`2[AppUI.Entries,System.String] 这是我的课程: public class Entries { public Entries() { } public Entries(string word) { t

当我用Xamarin和sqlite创建一个应用程序时。我运行了一条语句,但它在emulator屏幕上显示了这句话:System.Linq.Enumerable+SelectEnumerableInterator`2[AppUI.Entries,System.String]

这是我的课程:

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; }
这是DatabaseManager类。函数GetDef()是我推荐的语句

public class DatabaseManager
{
    SQLiteConnection dbConnection;
    public DatabaseManager()
    {
        dbConnection = DependencyService.Get<ISQLite>().GetConnection();
    }


    public string GetDef(string w)
    {
        return dbConnection.Table<Entries>().Where(x => x.word == w).Select(x => x.defn).ToString();
    }


}
公共类数据库管理器
{
SQLiteConnection-dbConnection;
公共数据库管理器()
{
dbConnection=DependencyService.Get().GetConnection();
}
公共字符串GetDef(字符串w)
{
返回dbConnection.Table().Where(x=>x.word==w);
}
}

我不知道为什么会这样?请帮忙。非常感谢您

查询的这一部分,Linq将返回一个
IEnumerable
(即零个或多个
条目
对象)

因此,使用
First
从枚举中获取第一条记录(如果不存在记录,则使用
FirstOrDefault
返回
null
):

返回dbConnection.Table()
.其中(x=>x.word==w)
.FirstOrDefault()?
.defn;

非常感谢您。我现在就试试。但它给出了另一个错误:“Entries”不包含“Select”的定义,并且找不到接受“Entries”类型的第一个参数的扩展方法“Select”(是否缺少using指令或程序集引用?@TanVuBoyGib I更新了答案以删除最终的
Select
.FirstOrDefault()?.defn;再次感谢你。你帮了我很多。我现在就试试。我试过了。这次它在模拟器屏幕上什么也没显示。我想:dbConnection.Table()。其中(x=>x.word==w)返回零,就像你说的一样。我对这条语句的想法是这样的:从word=w的条目中选择defn
dbConnection.Table<Entries>().Where(x => x.word == w)
.Select(x => x.defn).ToString();
return dbConnection.Table<Entries>()
          .Where(x => x.word == w)
          .FirstOrDefault()?
          .defn;