【发布时间】:2019-07-28 20:03:44
【问题描述】:
我有两个班级,Event 和 ScoutData
public class Event
{
[PrimaryKey]
public int ID
{
get; set;
}
public Event()
{
}
public Event(string start, string end, string name, int id, bool isCurrent)
{
startDate = start;
endDate = end;
eventName = name;
ID = id;
isCurrentEvent = isCurrent;
}
public string startDate
{
get; set;
}
public string endDate
{
get; set;
}
public string eventName
{
get; set;
}
public bool isCurrentEvent
{
get; set;
}
}
public class ScoutData
{
[PrimaryKey]
public int ID { get; set; }
public ScoutData()
{
}
// Some public properties, including a public Event from the other class
}
当我尝试将表添加到 sqlite 连接时
public EventDatabase()
{
_connection = DependencyService.Get<ISQLite>().GetConnection();
_connection.CreateTable<ScoutData>();
_connection.CreateTable<Event>();
}
Event 表生成正常,但ScoutData 表抛出此异常:
System.NotSupportedException: 不知道 App6.Event
ScoutData 类在其中使用 Event,但一切都是公开的。我尝试过重命名、清理等,但似乎无法弄清楚为什么 sqlite 会为某些类而不是其他类创建表。
【问题讨论】:
-
SQLite.NET 仅处理原始 .NET 类型。您要做的实际上是在两个表之间创建 FK 关系。有一个单独的 SQLite 扩展包可以让你做到这一点。
标签: c# android sql class xamarin