User defined relationships

Posts   
 
    
BlackMamba avatar
BlackMamba
User
Posts: 34
Joined: 30-Apr-2004
# Posted on: 11-May-2004 10:33:07   

Hi, in several projects I faced the need to user record coming from tables which are not part of my system. For example, in a web site for a local town, i needed to access data on the local town database. Usually what I do in these cases is create views with the information I want and treat them as normal tables to which I never write anything. In the past we had a sort of an in house ORM mapper that would let us create the relationships manually between tables and so in such situations we would create virtual relationships between the tables and those views.

With LLBLGen I guess it could be done by generating a real table in development and use it to make LLBLGen create the relationships etc, and then in production use the views instead.

I just wanted to know if you had a similar situation and how you solved it.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39826
Joined: 17-Aug-2003
# Posted on: 11-May-2004 10:37:21   

The data you want to relate to, is that data in your own database? If so, you can create the view in your db of course. Otherwise, I'm a bit puzzled where the data comes from, physically.

Frans Bouma | Lead developer LLBLGen Pro
BlackMamba avatar
BlackMamba
User
Posts: 34
Joined: 30-Apr-2004
# Posted on: 11-May-2004 10:45:35   

Otis wrote:

The data you want to relate to, is that data in your own database? If so, you can create the view in your db of course. Otherwise, I'm a bit puzzled where the data comes from, physically.

The data I want to relate to might or might not be in my own database. For example SQLServer can create views that get the data on other databases and possibly other machines.

Example:

My web site uses a table called PERSON in this table I have a field called cf_id.

My local town has a database with all the information on a citizen and the table is named CITIZEN with a primary key cf_id.

The cf_id on my PERSON table should be a foreign key on CITIZEN, but obviously this is not possible to achieve as CITIZEN already exists and is part of my local town db.

So, I guess the only way is to create a CITIZEN table in my database, use it in development, and in production replace it with a View that reads from LOCALTOWNDB.CITIZEN

We've done this before and it worked, I just wandered if it will work with LLBLGen generated code.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39826
Joined: 17-Aug-2003
# Posted on: 11-May-2004 12:17:15   

FOr the time being, I think that's also the best way with the generated code. Replace the name in the EntityFieldFactory file generated, to make it read from the linked table.

Am I correct in assuming that you have a PK in person which is an FK to 2 tables?

Frans Bouma | Lead developer LLBLGen Pro
Fishy avatar
Fishy
User
Posts: 392
Joined: 15-Apr-2004
# Posted on: 11-May-2004 15:59:49   

I had a similar situation were I needed a table from another database. I just created a view in my primary database and had llbl create a typed datatable.

BlackMamba avatar
BlackMamba
User
Posts: 34
Joined: 30-Apr-2004
# Posted on: 11-May-2004 16:55:32   

Fishy wrote:

I had a similar situation were I needed a table from another database. I just created a view in my primary database and had llbl create a typed datatable.

Yes but in this case you loose the information about the relationship between your table and the 'foreign' table. Basically the problem is how to best create a situation for LLBLGen to derive the correct shema and entity relationships equivalent to the situation where the tables are all in your db.