Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SQLite net PCL-简单选择_C#_Sqlite_Xamarin_Portable Class Library - Fatal编程技术网

C# SQLite net PCL-简单选择

C# SQLite net PCL-简单选择,c#,sqlite,xamarin,portable-class-library,C#,Sqlite,Xamarin,Portable Class Library,我使用windows应用程序中的SQLite,现在我正在Xamarin中开发一个便携式应用程序,因此我使用插件SQLite net pcl,我很难理解它是如何工作的 我有一个由te创建的表,如下所示: public class Config { public string IP { get; set; } [SQLite.Net.Attributes.Default(true, "Client 2")] public string ID {

我使用windows应用程序中的SQLite,现在我正在Xamarin中开发一个便携式应用程序,因此我使用插件SQLite net pcl,我很难理解它是如何工作的

我有一个由te创建的表,如下所示:

public class Config
    {
        public string IP { get; set; }
        [SQLite.Net.Attributes.Default(true, "Client 2")]
        public string ID { get; set; }
    }
List<string> hhid = db.Query<string>("select ID from Config",null);
要创建表,请执行以下操作:

db.CreateTable<Model.Config>();
db.CreateTable();
问题:现在我想选择ID列中的值,并执行以下操作:

public class Config
    {
        public string IP { get; set; }
        [SQLite.Net.Attributes.Default(true, "Client 2")]
        public string ID { get; set; }
    }
List<string> hhid = db.Query<string>("select ID from Config",null);
List hhid=db.Query(“从配置中选择ID”,null);
我得到这个异常:
“对象引用未设置为对象的实例”

如何进行简单的选择以查找此字段


谢谢你给我的任何提示,希望这对我身边的人有用

括号()之间是表名:

db.Query<TableName>("select * from ....");
db.Query(“选择*from…”);
一些对我有用的例子: 简单选择:
var list=db.Query(“从MyTableName中选择*);
有限制地选择:
var list=db.Query(“从MyTableName中选择*其中lastname=?和firstname=?”,lastnameValue,firstNameValue);

如果表名有自定义映射,则接受的答案实际上没有帮助。 “Sql”表名可以在访问类型映射的运行时找到

这里有一个扩展方法

公共静态类NativeConnectionExtension
{
公共静态列表SelectAllFrom(此SQLiteConnection cnn),其中T:new()
{
var mapping=cnn.GetMapping();
var result=cnn.Query(String.Format(“select*from{0};”,mapping.TableName));
返回结果;
}
}

列出hhid=db.Query(“从配置中选择id”,null)字段名称为
ID
ID
更改选择以匹配字段name@MethodMan我试过了,结果也一样。我现在更新的问题是
db
是否正确初始化?您是否尝试过LINQ语法而不是.Query?i、 e<代码>连接表()@nachogsiri你解决了吗?
public static class NativeConnectionExtension
{
    public static List<T> SelectAllFrom<T>(this SQLiteConnection cnn) where T : new()
    {
        var mapping = cnn.GetMapping<T>();
        var result = cnn.Query<T>(String.Format("select * from {0};", mapping.TableName));
        return result;
    }
}