概述: 我正在使用SQLLite查询Windows Phone 8.1解决方案中的现有数据库。我已经调整了这个solution来将数据库数据读回我的项目。但是当我使用数据库连接调用ToList()时,我得到一个没有这样的数据库错误的。如何解决SQLLite“没有这样的表”的错误?
到目前为止,我已经附加数据库文件和我的DBHelper类使用下面的代码来查询数据传回:
using (var dbConn = new SQLiteConnection(dbPath))
{
//No such table error thrown here ->
List<ZoneInfo> zoneInfo = dbConn.Table<ZoneInfo>().ToList<ZoneInfo>();
ObservableCollection<ZoneInfo> zoneInfoCollection = new ObservableCollection<ZoneInfo>(zoneInfo);
return zoneInfoCollection;
}
这是完整的DBHelper类从我的解决方法参考现有的数据库文件和将其复制到设备的本地文件夹。 DB文件本身是here。
调试步骤:
- 我回顾了区信息类的属性,以确定它们与该类型/名称每个字段在下面的DB模式匹配,和他们相匹配。
- dbPath名称与附加的数据库名称相匹配,所以这也不是问题。
- 我还发现一个similar question与Android上的SQLLite相关,这表明它可能是我在桌面上查询时遇到的一个问题。
- 我还考察了dbconn变量,它让我在错误的详细信息:
我应该采取什么步骤来调试SQLLite“没有表”的错误进一步?
异常详情: 异常的确切细节是如下这告诉我不存在这样的区信息表:
SQLite.SQLiteException was unhandled by user code
HResult=-2146233088
Message=no such table: ZoneInfo
Source=Parking Tag Picker WRT
StackTrace:
at SQLite.SQLite3.Prepare2(IntPtr db, String query)
at SQLite.SQLiteCommand.Prepare()
at SQLite.SQLiteCommand.<ExecuteDeferredQuery>d__0`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at SQLite.SQLiteCommand.ExecuteQuery[T]()
at SQLite.TableQuery`1.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Parking_Tag_Picker_WRT.Helpers.DatabaseHelper.ReadZones(String dbPath)
at Parking_Tag_Picker_WRT.ViewModel.TagRequestViewModel.InitZoneInfoAsync()
at Parking_Tag_Picker_WRT.TagRequestPage.OnNavigatedTo(NavigationEventArgs e)
InnerException:
区信息类别:(DB中的数据映射到一个类)
public class ZoneInfo
{
//The ObjectId property is marked as the Primary Key
[SQLite.PrimaryKey]
[Column("results_list_objectId")]
public string ObjectId { get; set; }
[Column("results_list_zone")]
public string ZoneName { get; set; }
[Column("results_list_tariff_ph")]
public int? TariffPH { get; set; }
[Column("results_list_tariff_pd")]
public int? TariffPD { get; set; }
[Column("results_list_restrictions")]
public string Restrictions { get; set; }
[Column("results_list_days_of_operation")]
public string DaysOpen { get; set; }
[Column("results_list_hours_of_operation")]
public string HoursOpen { get; set; }
public ZoneInfo()
{
}
public ZoneInfo(string objectId, string zoneName, int tariffPH, int tariffPD,
string restrictions, string daysOpen, string hoursOpen)
{
ObjectId = objectId;
ZoneName = zoneName;
TariffPH = tariffPH;
TariffPD = tariffPD;
Restrictions = restrictions;
DaysOpen = daysOpen;
HoursOpen = hoursOpen;
}
}
DB模式:
DB位置的解决方案:
我没有找到数据库中的ZoneInfo表。 –
确定没有,这是我的数据库应该映射到的POCO类的名称。是否应该与我的db文件名相同? DublinCityCouncilTable –