Serenity: Join table between databases

Created on 25 Mar 2019  路  3Comments  路  Source: serenity-is/Serenity

Hi all!

Is there an out-of-the-box method to join table from two or more different databases?

Some like this

Now I have try with a workaround but I want avoid to hardcode the database and table name

```c#
ForeignKey("[MySecondDatabase].[dbo].[MyTable]", "ID"), LeftJoin("jMyJoin")]

I try also with TableName on Row
```c#
[TableName("[MySecondDatabase].[dbo].[MyTable]")] 

and
c# [ForeignKey(typeof(MyRow), "ID"), LeftJoin("jMyJoin")]
and it works, but the database name is hardcoded. I want to get It from connection string indicated by ConnectionKey attribute

If there isn't I try to implement it in FrorignKey attribute

Most helpful comment

You can use [YourConnecitonKey^].sometable

All 3 comments

I am doing multi database requests using Oracle Database Link feature.
ConnectString is always same on all my objects (generic = [DbServices]).
Database Links resolves the "remote" objects transparently (they could have been local or remote, it works - database hides resolution) from that same Connectstring.

I have a database link on each tables (remote tables) + public synonyms on each schema tables/views.
This way i dont have to prefix tablename (necessarily hardcoded) with owner of the object.
I never use the SCHEMA.OBJECT NAME as some object can be deployed on various other DB so i want only one db creation script (objects are created in current schema during installation).

I have never tested with Sqlserver but looks like there is something similar (https://stackoverflow.com/questions/189422/how-do-i-create-and-query-linked-database-servers-in-sql-server)

You can use [YourConnecitonKey^].sometable

Wow, very good! Thank you @volkanceylan !

Thank you too @kilroyFR for your time :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GitHubOrim picture GitHubOrim  路  3Comments

newyearsoft picture newyearsoft  路  3Comments

Amitloh picture Amitloh  路  3Comments

ahsansolution picture ahsansolution  路  3Comments

Shraddha996 picture Shraddha996  路  3Comments