我試圖在SQlite兩個表之間建立一個簡單的關係。 I'm下面是創建此類指南:關於SQlite關係的初學者
public class Car
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string Brand { get; set; }
public int Milage { get; set; }
public int NumberOfWheels { get; set; }
}
在引導他創造這在其CTOR
public CarRepository(SQLiteConnection connection)
{
_connection = connection;
_connection.CreateTable<Car>();
}
在我自己的例子創建此表的存儲庫,我想添加第二個表Driver
public class Driver
{
public int DriverId { get; set; }
public string Name{ get; set; }
}
但是如何建立一個關係,如果一個司機可以有很多車?有了實體框架,我也只會說:
public virtual ICollection<Car> DriversCars { get; set; }
在Driver
-class和:
public virtual int DriverId { get; set; }
在汽車類。
是否有可能在SQlite中以類似的方式執行此操作,或者我可能必須以某種方式使用Sql語法?
這是.NET代碼? – 2015-02-10 09:52:57
是的,即時創建一個Windows應用程序。 – bugsy 2015-02-10 09:55:15
這裏是使用教程,雖然我只對windows-part感興趣: http://www.johankarlsson.net/2014/04/setting-up-sqlite-on-ios-android-and.html – bugsy 2015-02-10 09:56:34