Can you Map Entity Across 2 DB's?

Posts   
 
    
Posts: 6
Joined: 21-May-2008
# Posted on: 13-Jun-2008 01:03:41   

We want to leverage a standard web application as the basis for user registration on our site. It has it's own DB structure, and we want to build on it's "user" table.

It is possible to map an entity across two DB's, so that we have this:

BaseWebApp UserTable OurWebApp EnhancedUserTable

Where EnhancedUserTable just references UserTable and adds data fields above and beyond what's provided in the base?

Ideally LLBLGen inheritance could be used to see this as one entity.

Any feedback or suggestions appreciated.

LTG

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 13-Jun-2008 10:11:29   

Through inheritance, this indeed works: supertype is mapped to table A, subtype is mapped to table B, and through inheritance inherits the mappings on table A.

Be aware that to make this work, a pk-pk 1:1 relation has to exist between entity mapped on A and entity mapped on B.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 6
Joined: 21-May-2008
# Posted on: 13-Jun-2008 15:24:36   

Just to confirm, this can work across 2 different databases in SQL Server?

Thanks for your reply -

LTG

Otis wrote:

Through inheritance, this indeed works: supertype is mapped to table A, subtype is mapped to table B, and through inheritance inherits the mappings on table A.

Be aware that to make this work, a pk-pk 1:1 relation has to exist between entity mapped on A and entity mapped on B.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 13-Jun-2008 16:07:46   

hdgreetings.com wrote:

Just to confirm, this can work across 2 different databases in SQL Server?

Thanks for your reply -

LTG

Otis wrote:

Through inheritance, this indeed works: supertype is mapped to table A, subtype is mapped to table B, and through inheritance inherits the mappings on table A.

Be aware that to make this work, a pk-pk 1:1 relation has to exist between entity mapped on A and entity mapped on B.

Yes, just add both catalogs to your llblgen pro project. Sqlserver doesn't allow you to define FK constraints across catalogs but you can define the relation between the two entities in the designer, (between the two pk's) and then you can make one hte subtype of the other.

Frans Bouma | Lead developer LLBLGen Pro
tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 17-Jun-2008 18:37:06   

In regards to custom relations created in the LLBLGen designer, how does LLBLGen know if it's a 1-1 relation?

I created a custom relation like this recently expecting to get a one to one relation from it and ended up with a one to many.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 21-Jun-2008 06:49:52   

tprohas wrote:

In regards to custom relations created in the LLBLGen designer, how does LLBLGen know if it's a 1-1 relation?

Quoting the docs:

Physical representation in the data model and LLBLGen Pro entities The typical hierarchy mentioned above is realized in your datamodel with one table / view per entity. This means that for the hierarchy above you'll get an Employee table / view, a Manager table / view and a BoardMember table / view. The Employee table is the leading table, where you define the primary key for the entity to uniquely identify an entity instance in the database. As ID is a perfect candidate for this (1:1 relation between entity Employee and attribute) this will become the primary key. Manager and BoardMember get this same field, to identity the rows stored in these tables, though they're not new PK values, but have a foreign key constraint defined to the ID of the supertype, so Manager.ID has a foreign key constraint to Employee.ID and BoardMember has a foreign key constraint to Manager.ID. This way, referential integrity rules in the database make sure your data stored in the database is correct, also for derived entities.

And the important note:

Don't use surrogate keys on the subtype tables, it's important the PK of the subtype tables has the foreign key to the supertype's PK.

So, you must make your two entities like:

Supertype

SomeUniqueField (PK) SomeOtherField ...

SubType

SomeUniqueField (PK) SomeSpecificField ...

Then you will be able to make your 1:1 relation.

David Elizondo | LLBLGen Support Team
tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 25-Jun-2008 01:18:35   

Thanks so much for the answer. I just realized I should have been more specific.

I understand that this works based on the FK relationships designed in the schema. If your mapping relationships across catalogs there won't be any FK to map and the LLBLGen designer won't know that it's a one to one relation. It then by default creates a one to many as it doesn't know any better.

Do I understand this correctly?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 25-Jun-2008 09:44:29   

tprohas wrote:

Thanks so much for the answer. I just realized I should have been more specific.

I understand that this works based on the FK relationships designed in the schema. If your mapping relationships across catalogs there won't be any FK to map and the LLBLGen designer won't know that it's a one to one relation. It then by default creates a one to many as it doesn't know any better.

Do I understand this correctly?

It creates a 1:1 relation if: - the FK is the PK OR - the FK has a unique constraint.

if the FK is just a field, not the PK and doesn't have a unique constraint, it creates a 1:n relation. So if you could check if this is the case?

Frans Bouma | Lead developer LLBLGen Pro