Is possible to get Entity only by passing its name?

Posts   
 
    
Daniel_V
User
Posts: 5
Joined: 10-Jun-2006
# Posted on: 10-Jun-2006 01:08:08   

Hi, Im trying to make a query, but i have in variables this: table name, table field what i want to do is this: Select [table field] from [table name]

Is this possible using llblgen? Thanks a lot. Daniel

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 11-Jun-2006 11:46:55   

Could you elaborate a bit more about the situation this is used in? I ask this because you seem to have field and table names but you're working with llblgen pro, so field names and table names are hidden for you through entity names and entity field names...

Frans Bouma | Lead developer LLBLGen Pro
Daniel_V
User
Posts: 5
Joined: 10-Jun-2006
# Posted on: 12-Jun-2006 18:03:27   

Hi Otis, yes this is the situation I'm trying to get from database metadata, i mean i'm getting table names, fields and relation (table name, and join), in order to make a query. I have this information in variables and i use llblgen to generate the query, is this possible?

Thanks a lot.

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 13-Jun-2006 07:02:58   

Me too, I find ir hard to understand your situation.

How did your application get those table names and field names, without using/knowing entity and entityField names?

And why don't you use entities and entityFields instead?

rblinton
User
Posts: 12
Joined: 11-Apr-2006
# Posted on: 13-Jun-2006 16:49:23   

Daniel, please correct me if I'm wrong...but it sounds like you've got table(s) in your schema that define tables, fields, and relations. You are grabbing a record from this 'metadata' based on some key (like customer) and storing those details in memory variables...

A 'metadata' row may look something like this:

customerID, tableName, pkField1, field2, fieldetc, relationTable, relationFkField...

Now that you've got these columns in memory you'd like to perform a fetch using generated llblgen classes based on this 'dynamic' info...it may do something like...

SELECT m_pkfield1, m_field2, m_fieldetc, FROM m_tablename INNER JOIN m_relationtable ON m_relationFkField = m_pkField1

Am I on the right track?

Daniel_V
User
Posts: 5
Joined: 10-Jun-2006
# Posted on: 13-Jun-2006 18:13:44   

Yes, that is the situation, i am so sorry i did not get myself clear. I'm impelmenting a notification module, when something occurs there is a predefined message with some information on the db (parameters) these information is stored in the database as metadata, to create a query when showing the message.

The idea was to implement something like C's sprintf, "message has %p1". Then %P1 is really "Select username from user where userid = 10" and i have this:

Query field:

Table: User Field: username

Query predicate:

Table: User Field: UserId Value: 10

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 13-Jun-2006 23:57:44   

Are you always retrieving one field from one table, or could there be multiple tables and fields? You may look at creating a dynamic list that includes the fields that you want. To lookup the correct field index take a look at this post http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=750&HighLight=1 .

Daniel_V
User
Posts: 5
Joined: 10-Jun-2006
# Posted on: 14-Jun-2006 00:28:59   

Thanks a lot bbclub for the post, as a matter of fact i was almost getting there but i'm really sure i was going the right direction.

I'm retrieving one field from one or more tables.

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 14-Jun-2006 07:54:55   

I guess you may want to use something like reflection or .NET class Activator. But you should be storing Entity names and EntityField names, rather than table & column names.

Please check the following threads: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=6304 http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=6378 http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=549 http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=2019

mkamoski avatar
mkamoski
User
Posts: 116
Joined: 06-Dec-2005
# Posted on: 19-Jun-2006 17:47:06   

Daniel_V wrote:

Hi, Im trying to make a query, but i have in variables this: table name, table field what i want to do is this: Select [table field] from [table name]

Is this possible using llblgen? Thanks a lot. Daniel

Daniel_V--

FWIW, I am doing something similar and I am using Reflection.

The downside is that it requires one big ugly factory method that takes a type-name-as-String and returns an actual System.Type of the correct entity type. This is a minor downside, IMHO. This method will FailFast if the given type-as-String is not supported; so, it is easy to see any errors but (sadly) that is only at run-time. This one method has to be maintained manually but the rest of the processing is quite dynamic.

To support this, our requirements specify an administrative process called "RefreshMetaData" that analyzes a given set of directory paths, looks for DLLs or EXEs, reflects the AssemblyInfo and TypeInfo and PropertyInfo from each, smart-updates (add-new or update-existing or delete-orphan) the meta-data store, and then finishes. It is a run-on-schedule process and it actually is pretty fast. Then, the main application consumes the meta-data on-demand. Note that we do store Entity-Name information, not "table-name" as you note.

And so on.

So, the short answer is that Reflection does work for this sort of thing.

HTH.

Thank you.

--Mark Kamoski