How to make a foreign key in SQlite.net from c #

0

Hello friends I am working on a project of c # I am new to this and I can not find the way to declare a foreigner from a class with c # code I clarify that I am using the MVC model but I give you one of my classes

 class producto
{
    [SQLite.PrimaryKey, SQLite.AutoIncrement]
    public int id { get; set; }
    [SQLite.NotNull]
    public string nombre { get; set; }
    public string tipo { get; set; }
    public int numero { get; set; }
    [SQLite.NotNull]
    public string porcion { get; set; }
    //Si yo quiero una foranea como la declaro crei que seria asi
    // [SQLite.ForeignKey] 



}

}

I appreciate you if someone can guide me

    
asked by harriroot 05.04.2016 в 01:16
source

1 answer

1

You can not declare foreign keys with SQLite by default, however there is an extension for SQLite called SQLite Extensions , that allows you to use this type of relationship in the following way:

[ForeignKey(typeof(Stock))]
public int StockId { get; set; }
public DateTime Time { get; set; }
public decimal Price { get; set; }

Where "Stock" is the name of the table that contains the primary key, and the field "StockId" would be the field of the foreign key.

I hope it helps you, you tell us.

    
answered by 17.04.2016 / 18:45
source