Related Tables Across Two Databases

Posts   
 
    
usschad
User
Posts: 75
Joined: 11-Sep-2008
# Posted on: 11-Sep-2008 23:48:39   

I have a situation where I need to have two databases and have a table in each that need to be related.

By the way, I read this thred and I am already on track... http://llblgen.com/tinyforum/Messages.aspx?ThreadID=2185&HighLight=1.

To explain better, there is an Image database. My application database basically just needs to associate images with Cases. So in the application database there is a table called CaseImage with a CaseId and ImageId. I made ImageId the primary key. It holds the primary key of the Image table in the Image database thus creating a 1:1 relationship.

So my first step was to include the Image catalog and add the ImageEntity to the LLBLGen project. Then I created a custom 1:1 relationship so that now, my CaseImageEntity will have a ImageEntity field.

Now, I'm thinking that this should all work great except for one exception:

My application is designed to connect to multiple databases. And what I mean by this is, different clients use the same application but access a completely different database based on the url they use to access the application. So for each client, there will be two connection strings saved in the web.config

for example, I could have the following connection strings: Client1 connectionstring Client2 connectionstring Client3 connectionstring

Well, I had to do additional work to make this work because when I would assign the connection string to the DataAccessAdapter, it would not use the catalog name in the string. It would use the catalog name that was used to generate the code. So I used the following logic to make my adapter connect to the appropriate catalog:


adapter.CatalogNameUsageSetting = SD.LLBLGen.Pro.ORMSupportClasses.CatalogNameUsage.ForceName;

adapter.CatalogNameToUse = catalogName;

The catalogName was pulled from the connection string.

This worked just fine until this issue came up where I need to connect to the Image database. I want to Fetch my CaseImageEntity (from application catalog) and Prefetch the ImageEntity (from the image catalog). How do I specify the catalog name for different entities with a prefetch?

Or am I going to have to write my own logic to 'prefetch' the image data?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 20-Sep-2008 12:11:00   

(sorry for the late reply. Please next time post these kind of questions in 'General')

You should use the feature in adapter where you can specify per catalog name the new name to use, per call. You can pass a hashtable with name pairs and every catalog name is then overwritten with the name you specify.

So you have three catalogs: - Main - ImagesCustomer1 - ImagesCustomer2

your code is written locally with the catalogs - Main - Images

When your code executes a call for customer1, you have to overwrite 'Images' with 'ImagesCustomer1'. You do that with catalog name overwriting directly on the adapter. quote from the 'Adapter - DataAccessAdapter funtionality' manpage:

Multi name setting Preferred way of performing catalog name overwriting. To do this, create a new CatalogNameOverwriteHashtable (type provided by the SD.LLBLGen.Pro.ORMSupportclasses assembly). You can specify a CatalogNameUsageSetting, but this isn't required. You then add key-value pairs, where the key is the name to overwrite and the value is the name to overwrite it with. If you specify '*' as key, all catalog names will be set to the name specified as value, if CatalogNameUsageSetting is set to ForceName. Please see the LLBLGen Pro reference manual for more details on this object. The created CatalogNameOverwriteHashtable is then passable to the DataAccessAdapter constructor or you can set the CatalogNameOverwrites properties to an instance of this special hashtable.

Frans Bouma | Lead developer LLBLGen Pro