在 xamarin 表单 pcl 上执行查询时没有这样的 table sqlite
No such table sqlite when execute query on xamarin forms pcl
我在读取 SQLite 数据库上的 table 时遇到问题。
我的OBJ_Userclass:
namespace Fimap.Models
{
public class OBJ_User
{
public int DLR_Id { get; set; }
public string DLR_Username { get; set; }
public string DLR_Password_Hash { get; set; }
public object DLR_Nome { get; set; }
public string DLR_Cognome { get; set; }
public int DLR_Tipo { get; set; }
public string DLR_Azienda { get; set; }
public object DLR_Telefono { get; set; }
public object DLR_Email { get; set; }
public int DLR_Abilitato { get; set; }
public object DLR_Time_Zone { get; set; }
public object DLR_Country { get; set; }
public string DLR_Culture { get; set; }
public object DLR_Email1 { get; set; }
public object DLR_MCC_Modello_Alias { get; set; }
public object DLR_Anagrafica { get; set; }
public object DLR_Firma { get; set; }
public bool IsFIMAP { get; set; }
public bool IsSTANDARD { get; set; }
public bool IsDealerOrFimap { get; set; } //true dealer - false user
public object DLR_Tipo_Esteso { get; set; }
public object DLR_Abilitato_Esteso { get; set; }
}
}
我在 pcl 项目中的界面:
public interface IDatabaseConnection
{
SQLite.SQLiteConnection DbConnection();
}
Android
[assembly: Xamarin.Forms.Dependency(typeof(DatabaseConnection_Android))]
namespace Fimap.Droid
{
public class DatabaseConnection_Android : IDatabaseConnection
{
public SQLiteConnection DbConnection()
{
var dbName = "FimapDB.db3";
var path = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), dbName);
return new SQLiteConnection(path);
}
}
}
iOS
[assembly: Xamarin.Forms.Dependency(typeof(DatabaseConnection_iOS))]
namespace App.iOS
{
public class DatabaseConnection_iOS : IDatabaseConnection
{
public SQLiteConnection DbConnection()
{
var dbName = "FimapDB.db3";
string personalFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string libraryFolder = Path.Combine(personalFolder);
var path = Path.Combine(libraryFolder, dbName);
return new SQLiteConnection(path);
}
}
}
pcl连接(数据库右连接):
database = DependencyService.Get<IDatabaseConnection>().DbConnection();
查询:
var test = database.Query<OBJ_User>("SELECT * FROM OBJ_User");
当我启动查询时出现此错误:
SQLite.SQLiteException: no such table: OBJ_User
OBJ_User 在数据库中有一条记录。
为什么连接不映射 table ?
数据库变量正确连接到数据库 sqlite,我不明白,因为数据库没有从 sqlite 文件获取映射。
解决方案?
如果你想要其他信息,请在评论中写信给我,我会回答
SQLite 库不知道如何将类型对象的属性映射到 sqlite 列。 SQLite 库默认支持以下列类型:string、int、double、byte[]、DateTime.
我在读取 SQLite 数据库上的 table 时遇到问题。
我的OBJ_Userclass:
namespace Fimap.Models
{
public class OBJ_User
{
public int DLR_Id { get; set; }
public string DLR_Username { get; set; }
public string DLR_Password_Hash { get; set; }
public object DLR_Nome { get; set; }
public string DLR_Cognome { get; set; }
public int DLR_Tipo { get; set; }
public string DLR_Azienda { get; set; }
public object DLR_Telefono { get; set; }
public object DLR_Email { get; set; }
public int DLR_Abilitato { get; set; }
public object DLR_Time_Zone { get; set; }
public object DLR_Country { get; set; }
public string DLR_Culture { get; set; }
public object DLR_Email1 { get; set; }
public object DLR_MCC_Modello_Alias { get; set; }
public object DLR_Anagrafica { get; set; }
public object DLR_Firma { get; set; }
public bool IsFIMAP { get; set; }
public bool IsSTANDARD { get; set; }
public bool IsDealerOrFimap { get; set; } //true dealer - false user
public object DLR_Tipo_Esteso { get; set; }
public object DLR_Abilitato_Esteso { get; set; }
}
}
我在 pcl 项目中的界面:
public interface IDatabaseConnection
{
SQLite.SQLiteConnection DbConnection();
}
Android
[assembly: Xamarin.Forms.Dependency(typeof(DatabaseConnection_Android))]
namespace Fimap.Droid
{
public class DatabaseConnection_Android : IDatabaseConnection
{
public SQLiteConnection DbConnection()
{
var dbName = "FimapDB.db3";
var path = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), dbName);
return new SQLiteConnection(path);
}
}
}
iOS
[assembly: Xamarin.Forms.Dependency(typeof(DatabaseConnection_iOS))]
namespace App.iOS
{
public class DatabaseConnection_iOS : IDatabaseConnection
{
public SQLiteConnection DbConnection()
{
var dbName = "FimapDB.db3";
string personalFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string libraryFolder = Path.Combine(personalFolder);
var path = Path.Combine(libraryFolder, dbName);
return new SQLiteConnection(path);
}
}
}
pcl连接(数据库右连接):
database = DependencyService.Get<IDatabaseConnection>().DbConnection();
查询:
var test = database.Query<OBJ_User>("SELECT * FROM OBJ_User");
当我启动查询时出现此错误:
SQLite.SQLiteException: no such table: OBJ_User
OBJ_User 在数据库中有一条记录。 为什么连接不映射 table ? 数据库变量正确连接到数据库 sqlite,我不明白,因为数据库没有从 sqlite 文件获取映射。 解决方案?
如果你想要其他信息,请在评论中写信给我,我会回答
SQLite 库不知道如何将类型对象的属性映射到 sqlite 列。 SQLite 库默认支持以下列类型:string、int、double、byte[]、DateTime.