SQLite4Unity3d icon indicating copy to clipboard operation
SQLite4Unity3d copied to clipboard

How to Specify a foreign key constraint?

Open sonaliee opened this issue 8 years ago • 1 comments

I need to create a column with foreign key constraint,i have tried to make a table like #this

public class Student { [ForeignKey] public int Id{ get; set; } public string Name { get; set; } } This does not work.

sonaliee avatar Jun 07 '17 09:06 sonaliee

Did you succeed on this? I'm struggled on the same problem. The only way I could made works is adding a new column on table by ADD COLUMN and then creating the REFERECE to another table, but my Character:

using (var con = new SQLiteConnection(DbURL, ConnectionMode))
            {
                var cmd = con.CreateCommand($"ALTER TABLE Character ADD COLUMN SuperPowerID INTEGER REFERENCES SuperPower(ID);");
                cmd.ExecuteNonQuery();
                con.Close();
            }

But, I can't put a SuperPowerID property on my c# Character class because will throw an error of "duplicate name SuperPowerID".

Also, there's no decorator flag to set to a property to generate and Foreing Key...

So, basically, I think there's no way to automatically generate FKs by decorating Properties...

daybson avatar Sep 16 '19 01:09 daybson