This is a migrated thread and some comments may be shown as answers.

SQLite DB First DDL Foreign Key Issues

4 Answers 78 Views
Databases and Data Types
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Joshua
Top achievements
Rank 1
Joshua asked on 18 Jun 2015, 07:19 AM

Hello,

I have noticed two rather strange issues regarding DB first creation of an entity model for a SQLite database.

Consider the following DDL:

CREATE TABLE [Warehouses] (
    [pk_Warehouse_ID]   integer,
    [Name]  nvarchar(254) NOT NULL,
    PRIMARY KEY ([pk_Warehouse_ID]) CONSTRAINT [pk_Warehouses]
);
 
CREATE TABLE [Bins] (
    [pk_Bin_ID] integer,
    [fk_Warehouse_ID]   integer,
    [Name]  nvarchar(254) NOT NULL,
    PRIMARY KEY ([pk_Bin_ID]) CONSTRAINT [pk_Bins],
    CONSTRAINT [ref_Bins_Warehouses] FOREIGN KEY ([fk_Warehouse_ID]) REFERENCES [Warehouses]([pk_Warehouse_ID])
);

The above schema works fine when clicking "Update From Database..." in the rlinq designer in Visual Studio. The foreign key relationships are created and appear in the design view as expected.

However, remove the space between "FOREIGN KEY" and "([fk_Warehouse_ID])", recreate the database, update in the designer and suddenly it loses all relationships/associations.

Good line:

CONSTRAINT [ref_Bins_Warehouses] FOREIGN KEY ([fk_Warehouse_ID]) REFERENCES [Warehouses]([pk_Warehouse_ID])

Bad line:

CONSTRAINT [ref_Bins_Warehouses] FOREIGN KEY([fk_Warehouse_ID]) REFERENCES [Warehouses]([pk_Warehouse_ID])

4 Answers, 1 is accepted

Sort by
0
Joshua
Top achievements
Rank 1
answered on 18 Jun 2015, 07:30 AM

A slightly off topic question to go along with this:

When specifying a primary key column as NOT NULL in SQLite, automatic inserts when creating a new model instance and inserting it without a primary key do not work. Once I remove the NOT NULL flag from the schema, the auto increments work as expected for the primary key.

Is this as expected?

I haven't looked in to this issue too much, but I would assume that I can still specify the column as NOT NULL and expect it to be autopopulated from the entity model instead of causing a primary key violation (since it will default to 0 and a record with that PK already exists).

0
Boris Georgiev
Telerik team
answered on 22 Jun 2015, 04:11 PM
Hello Joshua,

Please excuse us for the inconvenience caused, it seems this is a bug on our side.
When there is no space between the FOREIGN KEY and the '(', then Telerik Data Access is not creating the association in the Domain Model. The workaround of this bug is to use only the SQL script which is generated by Telerik Data Access or to add a space between the FOREIGN KEY and the '(' bracket.

We are not aware for such an issue about using AutoInc Primary Key which is set to NOT NULL. If you are using the SQL script which you have sent in the first ticket, the Primary Key column is not set to be AutoInc. To set the Primary Key column to use the DatabaseServerCalculated Identity Mechanism, you could follow the guidance in this documentation article.

I hope that helps.

Regards,
Boris Georgiev
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
0
Joshua
Top achievements
Rank 1
answered on 23 Jun 2015, 12:54 PM

Hello Boris,

Thank you for confirming that the issue is not just user error!

Will there be a fix for this in the near future?

With regards to the AUTOINC column, we initially had it marked as such in our designer which we used in the database-first approach, but still didn't have any luck getting Data Access to recognise it as such. We used Database.NET to create our database if that's any use.

Regards

0
Boris Georgiev
Telerik team
answered on 25 Jun 2015, 03:47 PM
Hi Joshua,

There will be a fix for this issue in one of the next releases of Telerik Data Access. Unfortunately I am not able to give you a time frame when you can expect the fix and with the direction in which the Telerik Data Access will be developed, only the Fluent Mapping will take advantage from the fix and the users who are using Visual Designer will not get the bug fix. This is why I will recommend you to setup your model using Fluent Mapping instead of XML mapping(Domain Model).

Regarding the issue with the AutoInc Primary Key, we were not able to reproduce the issue in our test environment, therefore if you could send us a copy of the database schema and the model, will help us greatly to understand the issue and assist you in the best possible way.

I am looking forward to hearing from you.

Regards,
Boris Georgiev
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Tags
Databases and Data Types
Asked by
Joshua
Top achievements
Rank 1
Answers by
Joshua
Top achievements
Rank 1
Boris Georgiev
Telerik team
Share this question
or