DDL at runtime with LLBLGen

Posts   
1  /  2
 
    
pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 07-Nov-2007 01:36:30   

Backslash wrote:

Ok, finally have the first piece of code ready. Attached are the template changes, and bits of code to support dynamic fields on the generated entity classes. This is still a work-in-progress, so I'm sure there's still bugs to be worked out!

Next up is support for dynamic tables!

Hi,

I have a similar requirement to allow for dynamic fields and was wondering if you could provide samples of your supporting database tables (Objects, Field(s) etc.). The code is referencing them but I can't find the queries to create them in the attached code sample file.

Thank you very much, Patrick

smurrell
User
Posts: 59
Joined: 22-Feb-2007
# Posted on: 07-Nov-2007 11:09:21   

Backslash wrote:

Ok, finally have the first piece of code ready. Attached are the template changes, and bits of code to support dynamic fields on the generated entity classes. This is still a work-in-progress, so I'm sure there's still bugs to be worked out!

As for the user defined fields and tables, there is no need to use reflection to access their properties. All the actual values are stored in the entity's Fields collection. To read a value, you can use entity.Fields[fieldName].CurrentValue; and to set a value, use entity.SetNewFieldValue(fieldName, "New value"); You just have need to have a list of field names handy, which comes from the metadata that's saved when a field is added.

Next up is support for dynamic tables!

Hello Backslash

Did you manage to get the dynamic tables working?

Regards, Simon

pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 08-Nov-2007 04:23:45   

Hi,

has anybody got the sample code from Backslash to work? (http://www.llblgen.com/tinyforum/GotoMessage.aspx?MessageID=59404&ThreadID=8232)

There seems to be a bug in it so that the dynamic fields will not be used for CRUD database operations e.g fetches and updates. For example this function call: FieldInfoProviderSingleton.GetInstance().GetFieldInfos(entityName); returns only the actual fields in the physical table and not the dynamically added fields.

 // This function creates the entity fields based on the data in FieldInfoProviderSingleton
 internal static IEntityFields2 CreateAllEntityFields(string entityName)
 {
  int fieldIndex = 0;
[b]IFieldInfo[] fieldInfos = FieldInfoProviderSingleton.GetInstance().GetFieldInfos(entityName);[/b]
  EntityFields2 entityFields = new EntityFields2(fieldInfos.Length);

  // Add the fields to the object, and always add to the end
  foreach (IFieldInfo field in fieldInfos)
  {
   entityFields.DefineField(new EntityField2(field), fieldIndex);
   fieldIndex++;
  }
  return entityFields;
 }

I would be grateful for any tips which help me to get this to work. Thanks a lot, Patrick

PS: The sample code was missing database tables. Attached you find the tables I inferred from the code.

Attachments
Filename File size Added on Approval
DynamicFieldsTables.sql 3,720 08-Nov-2007 04:24.20 Approved
orm_novice
User
Posts: 4
Joined: 08-Nov-2007
# Posted on: 08-Nov-2007 15:46:23   

I am new to ORM and its concept.

Please pardon me, if some one has already posted similar questions.

Currently I am evaluating LLBLGen Pro, it seems a great product. I have few questions regarding database schemas and dynamic tables.

  1. We have a product which spans across multiple schemas and database server, internally we use lots of syonynyms and database links.

how can we set the schema names at runtime, how to use database links.

  1. Other questions is about dynamic tables, we have master table, for every record in the master table, we create one dynamic table to store the details. These dynamic tables have exactly same fields, constraints etc.

Is there way to set the table names in the Entity classes at runtime.

I would greatly appreciate some help in this regards. orm_novice.confused

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 08-Nov-2007 18:06:32   

orm_novice wrote:

I am new to ORM and its concept.

Please pardon me, if some one has already posted similar questions.

Please next time open a new thread, thanks wink

Currently I am evaluating LLBLGen Pro, it seems a great product. I have few questions regarding database schemas and dynamic tables.

  1. We have a product which spans across multiple schemas and database server, internally we use lots of syonynyms and database links.

how can we set the schema names at runtime, how to use database links.

Database links aren't supported, though synonyms of tables/views are supported as well as synonyms of sequences. You don't name the database type, so I assume it's oracle.

Database links aren't supported because meta-data retrieval is often cumbersome because meta-data of the tables in the linked server isn't always obtainable.

You can work around this by creating a schema you want to work with and create the llblgen pro project with that schema, then at runtime redirect the schema reference to the real schema by using 'schema name overwriting'. See 'Using the generated code -> Application configuration through config files' in the manual.

  1. Other questions is about dynamic tables, we have master table, for every record in the master table, we create one dynamic table to store the details. These dynamic tables have exactly same fields, constraints etc.

Is there way to set the table names in the Entity classes at runtime.

Not without programming. Use adapter, and you can then derive a class from DataAccessAdapter and override for example the OnSaveEntity() method which receives the query for the save to process. You can then replace the table name with the name you want.

Alternatively, you can also use an override of GetFieldPersistenceInfo(s), and create a NEW FieldPersistenceInfo object where you copy the data you retrieve from the base method over to the new construct, except the table name, which you replace by a new name.

You can decide which names to replace with what by for example passing a list of name-value pairs to your derived class of DataAccessAdapter and obtain the name to use from that list. Adapter lets you use a DataAccessAdapter instance per call, so you can control this per action on the db.

Frans Bouma | Lead developer LLBLGen Pro
orm_novice
User
Posts: 4
Joined: 08-Nov-2007
# Posted on: 08-Nov-2007 18:40:03   

Thanks for your response.

Regarding the schema name changes you explaination helped me a lot.

But regarding the dynamic table name question. Do you have samples for DataAccessAdapter derived class that I can refer to. That will really save me lots of time.

Basically I need to understand after deriving the class where to set the tablename, fields and relations

Thanks in advance.

Otis wrote:

orm_novice wrote:

I am new to ORM and its concept.

Please pardon me, if some one has already posted similar questions.

Please next time open a new thread, thanks wink

Currently I am evaluating LLBLGen Pro, it seems a great product. I have few questions regarding database schemas and dynamic tables.

  1. We have a product which spans across multiple schemas and database server, internally we use lots of syonynyms and database links.

how can we set the schema names at runtime, how to use database links.

Database links aren't supported, though synonyms of tables/views are supported as well as synonyms of sequences. You don't name the database type, so I assume it's oracle.

Database links aren't supported because meta-data retrieval is often cumbersome because meta-data of the tables in the linked server isn't always obtainable.

You can work around this by creating a schema you want to work with and create the llblgen pro project with that schema, then at runtime redirect the schema reference to the real schema by using 'schema name overwriting'. See 'Using the generated code -> Application configuration through config files' in the manual.

  1. Other questions is about dynamic tables, we have master table, for every record in the master table, we create one dynamic table to store the details. These dynamic tables have exactly same fields, constraints etc.

Is there way to set the table names in the Entity classes at runtime.

Not without programming. Use adapter, and you can then derive a class from DataAccessAdapter and override for example the OnSaveEntity() method which receives the query for the save to process. You can then replace the table name with the name you want.

Alternatively, you can also use an override of GetFieldPersistenceInfo(s), and create a NEW FieldPersistenceInfo object where you copy the data you retrieve from the base method over to the new construct, except the table name, which you replace by a new name.

You can decide which names to replace with what by for example passing a list of name-value pairs to your derived class of DataAccessAdapter and obtain the name to use from that list. Adapter lets you use a DataAccessAdapter instance per call, so you can control this per action on the db.

orm_novice
User
Posts: 4
Joined: 08-Nov-2007
# Posted on: 08-Nov-2007 22:29:57   

Regarding tables that are generated at runtime.

We can derive a class from DataAccessAdapter and use it using OnSaveEntity().

Can some one please provide me some example about this.

In my database i have table called ITEM_MASTER which has all the constraints defined.

The application will create a new table ITEM_<MMDDYYYY_ID> using ITEM_MASTER as template.

Daily there around 1000 tables created.

Using the derived class from DataAccessAdapter how can set the table names and relations.

I would really appreciate any help in this.

Regards orm_novice

pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 08-Nov-2007 22:48:42   

orm_novice wrote:

We can derive a class from DataAccessAdapter and use it using OnSaveEntity().

Not exactly what you are looking for but better than nothing simple_smile An example of replacing a table name in a query with the DataAccessAdapter http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=11573&StartAtMessage=0&#64617

Hope it helps, Patrick

(snip-- otis)

pat wrote:

has anybody got the sample code from Backslash to work? There seems to be a bug in it so that the dynamic fields will not be used for CRUD database operations e.g fetches and updates.

This thread here continues my question from above by the way http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=11806

Posts: 32
Joined: 01-Oct-2007
# Posted on: 05-Dec-2007 16:10:08   

smurrell wrote:

Backslash wrote:

Ok, finally have the first piece of code ready. Attached are the template changes, and bits of code to support dynamic fields on the generated entity classes. This is still a work-in-progress, so I'm sure there's still bugs to be worked out!

As for the user defined fields and tables, there is no need to use reflection to access their properties. All the actual values are stored in the entity's Fields collection. To read a value, you can use entity.Fields[fieldName].CurrentValue; and to set a value, use entity.SetNewFieldValue(fieldName, "New value"); You just have need to have a list of field names handy, which comes from the metadata that's saved when a field is added.

Next up is support for dynamic tables!

Hello Backslash

Did you manage to get the dynamic tables working?

Regards, Simon

Hi Backslash

Any more progress on dynamic tables...?

Cheers

Matt

rlmartins
User
Posts: 5
Joined: 03-Oct-2016
# Posted on: 09-Jan-2021 16:12:13   

Backslash wrote:

Ok, finally have the first piece of code ready. Attached are the template changes, and bits of code to support dynamic fields on the generated entity classes. This is still a work-in-progress, so I'm sure there's still bugs to be worked out!

As for the user defined fields and tables, there is no need to use reflection to access their properties. All the actual values are stored in the entity's Fields collection. To read a value, you can use entity.Fields[fieldName].CurrentValue; and to set a value, use entity.SetNewFieldValue(fieldName, "New value"); You just have need to have a list of field names handy, which comes from the metadata that's saved when a field is added.

Next up is support for dynamic tables!

Backslash , Many years have passed, but i am wondering if you ever got the dynamic tables and fields working properly with LLBLGen Pro adapter template for SQL Server.

Thanks RM

1  /  2