Page 1 of 1

Foreign keys between different schemas (mysql + NH)

Posted: Mon 19 Mar 2018 13:36
by DarkCamper
Hi!

I have a problem when generating a model from a DB that has a table with a FK to a table in another schema. Entity Developer doesn't seem to acknowledge that the FK exists and no association between both entities is created.
If I create the association manually and then try to update the DB from the Model it says a FK needs to be created.

You can reproduce it following these steps:
1. Create two databases in mysql. Call them "SchA" an "SchB"
2. Run the following SQL Script to create 3 tables and some FKs

Code: Select all

create table SchB.TableB(id int primary key);
create table SchA.TableC(id int primary key);
create table SchA.TableA(
  id int primary key, 
  id_B int,
  id_C int, 
  FOREIGN KEY FK_TEST_B(id_B) REFERENCES SchB.TableB(id),
  FOREIGN KEY FK_TEST_C(id_C) REFERENCES SchA.TableC(id));
3. Create a new NHibernate model, DB First, and select all tables from SchA and SchB
4. The result will be something like this
Image

As you can see no association between TableA and TableB has been created, but the association between TableA and TableC has been correctly added.

I've tested this with Entity Developer Pro 6.2.439 and MySql 5.6.25

Thanks!

Re: Foreign keys between different schemas (mysql + NH)

Posted: Thu 22 Mar 2018 18:47
by Shalex
Thank you for your report. We will notify you when the issue is fixed.

Re: Foreign keys between different schemas (mysql + NH)

Posted: Fri 27 Apr 2018 11:08
by Shalex
The new Retrieve Cross Database Relations option is implemented in Model Settings (Tools > Options > Servers' Options > MySQL) for detecting FK relations between tables in different databases. Please upgrade to dotConnect for MySQL v8.10.1134.

Leads to performance loses when retrieving metadata, you should increase value of the Default Command Timeout connection string parameter.

Re: Foreign keys between different schemas (mysql + NH)

Posted: Thu 31 May 2018 10:51
by DarkCamper
I've just tested the new "Retrieve Cross Database Relations" option and it seems to work just fine :)

Thanks a lot!