mardi 10 février 2015

Beginner about SQlite relations

Im trying to set up a simple reltion between two tables i SQlite. I´m following a guide that creates this class:



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; }
}


In the guide he creates a repository which creates this table in its CTOR



public CarRepository(SQLiteConnection connection)
{
_connection = connection;
_connection.CreateTable<Car>();
}


In my own example I would like to add a second table called Driver



public class Driver
{

public int DriverId { get; set; }
public string Name{ get; set; }

}


But how can I Set up a relationship if one driver can have many cars? With entity framework I would simply have added:



public virtual ICollection<Car> DriversCars { get; set; }


In the Driver-class and:



public virtual int DriverId { get; set; }


in the Car-class.


Is it possible to do this in a similar way in SQlite or do I maybe have to use the Sql-syntax in some way?


Aucun commentaire:

Enregistrer un commentaire