Is it possible to determine the entity type from a db table name?

Posts   
 
    
Sokon1
User
Posts: 97
Joined: 17-Jul-2006
# Posted on: 04-Jan-2007 11:48:37   

Hi,

I've got a list of db table names (strings). Now I'd like to create entity instances. As an example there is a db table called "tbl_blabla" and in my code i have the according entity type "BlablaEntity". My application should read the list's "tbl_blabla" and create a new instance of "BlablaEntity".

Is that possible? How?

Thanks in advance!

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 04-Jan-2007 16:01:02   

Why don't you use the entityTypes rather than the table names?

refer to the following thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=8150 http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=8493

Another solution: To use the above approach yet to loop through all available entities (create an instance for each) and check the Table name inside (SourceObjectName). http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=3628

An easy solution: To use the templates to generate a method which doe sthe trick for you http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=4884 (code generation knows the table_name / entity_name mapping)

Sokon1
User
Posts: 97
Joined: 17-Jul-2006
# Posted on: 05-Jan-2007 09:39:23   

Hi Walaa, thanks for your response.

Walaa wrote:

Why don't you use the entityTypes rather than the table names?

refer to the following thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=8150 http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=8493

I can't use reflection because the list is created by database triggers which don't know any entity names.

Walaa wrote:

Another solution: To use the above approach yet to loop through all available entities (create an instance for each) and check the Table name inside (SourceObjectName). http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=3628

If I understand that post correctly, I need a field to determine the type of the entity. But I don't have a field, only a string.

Walaa wrote:

An easy solution: To use the templates to generate a method which doe sthe trick for you http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=4884 (code generation knows the table_name / entity_name mapping)

That post doesn't seem to be the post you wanted to show me. wink

The class "PersistanceInfoProvider" in self servicing scenario seems to do the mapping between entity type and table name. I want to use Adapter scenario, so perhaps there's something similar, which i could access.

Or is there a list of all entity types of the current data project, created by LLBLGen? I could loop over it an determine the tables names by using the idea of the third post from above. (But this seems rather complicated.)

P.S.: Using Adapter Scenario, C#, LLBLGen 2.0.0.0 Dec 6th 2006

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 05-Jan-2007 10:33:43   

I think a template approach is best. In short: a template which generates a statically constructed singleton hashtable which contains per table name the entity type enum value (so you can utilize the generalentityfactory)

You can use this single template with your regular preset and generate that extra class into the generated code so it's always up to date. If you need help with writing that template, let us know.

Frans Bouma | Lead developer LLBLGen Pro
Sokon1
User
Posts: 97
Joined: 17-Jul-2006
# Posted on: 05-Jan-2007 10:47:06   

Thanks for your answer.

I'm going to try it with the templates. I'm sure I'll come back to this thread while doing that, but for the time being let's close this thread.