Hi friends, I'm working on a C# project, I'm new to this, and I can't find a way to declare a foreign from a class with C# code. I clarify that I'm using the MVC model, but I'm providing you with 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 if someone can guide me
You can't declare foreign keys with SQLite by default, however there is an extension to SQLite called SQLite Extensions , which allows you to use foreign keys like this:
Where "Stock" is the name of the table that contains the primary key, and the "StockId" field would be the foreign key field.
I hope it helps you, let us know.