Pseudo-inheritance and primary keys
Posted: Fri 24 Dec 2010 17:31
In my project, I have abstracted out persistence so that I can plug in currently either SQL Server or SQLite. For SQL Server I am using the VS 2008 built-in SQL-to-LINQ model generator.
The database has been designed to map directly to the objects that are represented, with inheritance implemented as a 1-1 relationship on primary keys between parent and child tables.
The 'base' table is called 'Entity', and contains various bits of metadata about object instances. This has a primary key (now 64 bit int, to get around a previous issue) with autoincrement.
All the other tables 'inherit', some indirectly, from the Entity table. They pick up their ID once the Entity record has been inserted. Or at least they are supposed to, and this works with the SQL Server version.
However, for the SQLite version, while the Entity record is inserted OK, the ID of the Entity instance is not passed back and used as the ID of the inheriting record/object i.e. while the records in the Entity table have an ID of 1, 2, 3, 4 ... etc., the other tables all have IDs of 1, 1, 1, 1 ... etc.
Am I missing something in the configuration of my dotConnect LINQ model? I can provide the database and model if needed. Thanks.
The database has been designed to map directly to the objects that are represented, with inheritance implemented as a 1-1 relationship on primary keys between parent and child tables.
The 'base' table is called 'Entity', and contains various bits of metadata about object instances. This has a primary key (now 64 bit int, to get around a previous issue) with autoincrement.
All the other tables 'inherit', some indirectly, from the Entity table. They pick up their ID once the Entity record has been inserted. Or at least they are supposed to, and this works with the SQL Server version.
However, for the SQLite version, while the Entity record is inserted OK, the ID of the Entity instance is not passed back and used as the ID of the inheriting record/object i.e. while the records in the Entity table have an ID of 1, 2, 3, 4 ... etc., the other tables all have IDs of 1, 1, 1, 1 ... etc.
Am I missing something in the configuration of my dotConnect LINQ model? I can provide the database and model if needed. Thanks.