Note that there are some explanatory texts on larger screens.

plurals
  1. POSubSonic not recognizing SQLite foreign keys
    text
    copied!<p>I'm using SubSonic 3.0.0.3 and I can't seem to get the ActiveRecord .tt files to recognize and generate code for the foreign keys and relationships in my SQLite database. </p> <p>I think it generates everything else just fine, but after looking at other snippets online it looks like there should be more generated code than just single classes in <code>ActiveRecord.cs</code> and <code>Structs.cs</code> for each of my tables. Looking inside <code>Structs.cs</code>, <code>IsForeignKey</code> is always <code>false</code> for every column, even the ones I have a foreign key defined for. Additionally, each <code>Foreign Keys</code> region is empty within each generated ActiveRecord class.</p> <p>I'm using VS2008 with references to SubSonic 3.0.0.3, System.Data.SQLite 1.0.66.0, and System.Data.SQLite.Linq 2.0.38.0 in my project. I created the database using SQLite Expert Personal 3.1.0.2076. I made some dummy tables to try to test out how SubSonic handles one:many and many:many relationships. Here's the DDL SQLite Expert spits out for my small database:</p> <pre><code>CREATE TABLE [Person] ( [PersonID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [PersonName] TEXT NOT NULL, [PersonAge] INT NOT NULL ); CREATE TABLE [Group] ( [GroupID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [GroupName] TEXT NOT NULL, [GroupDescription] TEXT NOT NULL ); CREATE TABLE [Dog] ( [DogID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [PersonID] INT NOT NULL CONSTRAINT [DogPersonFK] REFERENCES [Person]([PersonID]) ON DELETE CASCADE ON UPDATE CASCADE, [DogName] TEXT NOT NULL); CREATE TABLE [GroupPersons] ( [GroupID] INTEGER NOT NULL CONSTRAINT [GroupPersonToGroupFK] REFERENCES [Group]([GroupID]) ON DELETE CASCADE ON UPDATE CASCADE, [PersonID] INTEGER NOT NULL CONSTRAINT [GroupPersonToPersonFK] REFERENCES [Person]([PersonID]) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT [sqlite_autoindex_GroupPersons_1] PRIMARY KEY ([GroupID], [PersonID])); </code></pre> <p>I know foreign keys are enabled and work in the database - SQLite Expert says they're on and when I change data in one place, like Person's PersonID, it does indeed change that PersonID in the Dog and GroupPersons tables. I've tried re-adding the database to the project, 'running custom tool' to get the .tt files to execute again, and even deleting them and adding them back. I can get a simple project to build that perform simple querying and insertions, however I tried just now to change the primary key of a single Person, Dog, or Group and x.Save() but System.Data.SQLite threw an exception for all three, saying <code>SQLite error near "WHERE":syntax error.</code> at the Save().</p> <p>Any suggestions for what I should try to do next?</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