Mapping tables with the same structure

Posts   
 
    
AK
User
Posts: 5
Joined: 27-Jan-2016
# Posted on: 06-Feb-2017 20:26:08   

We have llblgen pro library (ver 4.2 Final, October 3rd, 2014) and we are using Template group: Adapter.

We need to implement a situation similar to Horizontal partitioning: we will have the same database table 'cloned' multi times. The tables will have exactly the same structure and will differ only with part of their names (solution1) or schemas (solution2). Both solutions will be ok for us. So for example:

solution1: dbo.my_table_1 dbo.my_table_2 dbo.my_table_3

solution2: s1.my_table s2.my_table s3.my_table

The tables have the same structure, so we would like to map my_table to only one 'table equivalent' in llblgen orm model - for eg. Entity called: MyTable. The tables will be created automatically multi-times per day - when new customer creates account in our system, so we can't refresh llblgen every time.

How to achieve it with llblgen? How to pass table or schema name down to its engine. We wouldn't like to use partitioned views and we don't have SqlServer in version which has built-in transparent partitioning.

Thank you in advance for your help.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 07-Feb-2017 10:05:39   

(October 3rd, 2014 is a really old build, please download the latest build of v4.2 from the website simple_smile )

Solution 1 isn't possible as that would mean you have to alter the mappings at runtime. Option 2 however is possible, with schema name overwriting. http://www.llblgen.com/Documentation/4.2/LLBLGen%20Pro%20RTF/hh_goto.htm#Using%20the%20generated%20code/Adapter/gencode_dataaccessadapter_adapter.htm#Schemaspecificpersistenceinfo

(see for an example the v5.1 docs: http://www.llblgen.com/Documentation/5.1/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/Adapter/gencode_dataaccessadapter_adapter.htm#specifying-overwrites-in-code-1)

You can do this per call in Adapter, by passing to the DataAccessAdapter a set of overwrites which will be done for all queries executed on that DataAccessAdapter from that point. You can also define these overwrites in the application config file or just once on the DataAccessAdapter, in case of when the schema name has to be overwritten always.

Hope this helps simple_smile

Frans Bouma | Lead developer LLBLGen Pro
AK
User
Posts: 5
Joined: 27-Jan-2016
# Posted on: 07-Feb-2017 20:32:18   

Thanks for help! Yes, we will download newer bulid, thanks.

**What you suggested sounds clear **smile So we will need to use schemas.

One more question. As I mentioned - every user in our system will have it's own clone of the same table. But not all our tables will be cloned. Some of them will be common for all users - only one representation of table. We will have TypedList which are joining the cloned-table with single-tables.

So for example, lets say that TypedList is doing something like: SELECT s1.contacts., dbo.contacts_groups. FROM s1.contacts INNER JOIN dbo.contacts_groups ON s1.contacts.id = dbo.contacts_groups.contact_id

s1.contacts - instance of cloned table dbo.contacts_groups - always single table

If I create new Adapter with

var overwrites = new SchemaNameOverwriteHashtable();
overwrites.Add("dbo", "s1");
adapter.FetchTypedList(......)

It will apply to all schemas under this TypedList cry (for contacts_groups and contacts table)

**How to make SchemaNameOverwrite more selective. Tell it - do your job only for tables like: contacts, abc, def, etc **

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 08-Feb-2017 20:23:21   

SchemaNameOverwrites work on a specific schema or per schema.

i.e. you can have a default schema for the common tables, say "dbo" then you can have another schema at development time, say "dev" which would need to be altered at runtime per user, so at runtime and per call, using the SchemaNameOverwrites, you can alter "dev" to "user1", while "dbo", remain untouched.

AK
User
Posts: 5
Joined: 27-Jan-2016
# Posted on: 14-Feb-2017 17:47:59   

Walaa, thanks for answer. So, to be brief - there's no way to achieve this sql with llblgen?

SELECT s1.contacts., dbo.contacts_groups. FROM s1.contacts INNER JOIN dbo.contacts_groups ON s1.contacts.id = dbo.contacts_groups.contact_id

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 14-Feb-2017 18:03:24   

You got me wrong. Sure you can achieve it.

SchemaNameOverwrites would take care of injecting the right schema names in the generated SQL.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 15-Feb-2017 09:55:28   

Indeed, simply keep the tables which are shared among all instances (the 'non-clones') in e.g. 'dbo', and the tables which are cloned over every instance in a separate schema (e.g. 'shared'). Then overwrite 'shared' with the name you need to use at runtime. This leaves 'dbo' stay 'dbo'.

Frans Bouma | Lead developer LLBLGen Pro
AK
User
Posts: 5
Joined: 27-Jan-2016
# Posted on: 21-Feb-2017 08:44:40   

Walaa, Otis thanks for help. We will use the SchemaNameOverwrites to overwriting name of schema to use it at runtime.

I have a question with creation the "New Typed List" in LLBLGen environment. As I mentioned I have two schemas ('dbo' and 'sample') and now I need to create a new TypedList with using these two different schemas. In the New TypedList creator when I choose a table from 'dbo' schema then all tables from 'sample' schema there are disabled. I attach screenshot.

I would like to achieve something as below:

SELECT dbo.Groups.Id, dbo.Groups.Name FROM dbo.Groups INNER JOIN sample.ContactsGroups1 ON dbo.Groups.Id = sample.ContactsGroups1.GroupId

How to solve it with TypedList?

Attachments
Filename File size Added on Approval
llblgen.png 33,252 21-Feb-2017 08:44.52 Approved
Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 21-Feb-2017 20:41:15   

I can't reproduce it.

Most probably there is no relation between the 2 tables. When you add an entity to the TypedList, all other non-related entities are dimmed out, and only those with defines relations are still available for addition.