Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It seems that the FKTables attribute for each table is not assigned in the file "SQLite.ttinclude". So i add some lines of code and managed to generate foreign key code :</p> <p>After line 16 (var schema = conn.GetSchema("COLUMNS");), insert :</p> <pre><code>var schemaForeignKeys = conn.GetSchema("FOREIGNKEYS"); </code></pre> <p>After line 29 (tbl.Name = row["TABLE_NAME"].ToString();), insert :</p> <pre><code>tbl.FKTables = new List&lt;FKTable&gt;(); var foreignKeyTables = schemaForeignKeys.Select("TABLE_NAME='" + tbl.Name + "'"); foreach (var foreignKeyTable in foreignKeyTables) { FKTable foreignKey = new FKTable(); foreignKey.ThisTable = foreignKeyTable["TABLE_NAME"].ToString(); foreignKey.ThisColumn = foreignKeyTable["FKEY_FROM_COLUMN"].ToString(); foreignKey.OtherTable = foreignKeyTable["FKEY_TO_TABLE"].ToString(); foreignKey.OtherColumn = foreignKeyTable["FKEY_TO_COLUMN"].ToString(); foreignKey.OtherClass = CleanUp(foreignKey.OtherTable); foreignKey.OtherQueryable = foreignKey.OtherClass; tbl.FKTables.Add(foreignKey); } </code></pre> <p>And after line 53 (col.IsNullable=row["IS_NULLABLE"].ToString()=="True";), insert :</p> <pre><code>col.IsForeignKey = tbl.FKTables.Any(x =&gt; x.ThisColumn == col.Name); </code></pre> <p>This is for generate the foreign key code.</p> <p>Moreover, you have maybe encounter a problem when you have to delete a record which has a column to be a foreign key in an other table ? For exemple : Person(Id, Name) Dog(Id, #PersonId) If you have set the #PersonId foreign key on-delete action to "SET TO NULL", this won't work because foreign key support is disabled by default in SQLite 3.6.23.1 (version used by Data.SQLite 1.0.66.0). To enable foreign key support, you have to execute this command with each connection :</p> <pre><code>PRAGMA foreign_keys = ON; </code></pre> <p>Now, this is not supported by Data.SQLite, but it will (in version 1.0.67.0, <a href="http://sqlite-dotnet2.cvs.sourceforge.net/viewvc/sqlite-dotnet2/SQLite.NET/System.Data.SQLite/SQLiteConnection.cs?r1=1.80&amp;r2=1.81" rel="nofollow noreferrer">http://sqlite-dotnet2.cvs.sourceforge.net/viewvc/sqlite-dotnet2/SQLite.NET/System.Data.SQLite/SQLiteConnection.cs?r1=1.80&amp;r2=1.81</a>).</p> <p>So you have to wait for the release or you can (like me) download the Data.SQLite source and compile the last version. It work great for me.</p> <p>Good luck. And sorry for my english :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload