Selecting collection, entity objects dynamically

Posts   
 
    
stoneyowl avatar
stoneyowl
User
Posts: 62
Joined: 29-Jan-2004
# Posted on: 03-Nov-2005 21:59:36   

I have a vague feeeling i have seen this before, but my search terms have not found it...

Is it possible to create a collectoin using only the name of the (SQL Server) table?

IE: if I pass 'MASTER_TABLE_DATA' to this hypothetical method, how do I go about getting a MasterTableDataCollection returned?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 04-Nov-2005 10:55:29   

stoneyowl wrote:

I have a vague feeeling i have seen this before, but my search terms have not found it...

Is it possible to create a collectoin using only the name of the (SQL Server) table?

IE: if I pass 'MASTER_TABLE_DATA' to this hypothetical method, how do I go about getting a MasterTableDataCollection returned?

You should work with entity names. You can then use the Activator class, which is a .NET class to instantiate objects by using a type name in a string.

So you pass in MasterTableData as name, and attach to that 'Collection'. You then create an instance of that collection with the Activator class and assign it to a variable of type IEntityCollection.

You then call GetMulti(null, ... ) on that variable. Et viola simple_smile

Frans Bouma | Lead developer LLBLGen Pro
stoneyowl avatar
stoneyowl
User
Posts: 62
Joined: 29-Jan-2004
# Posted on: 04-Nov-2005 18:10:39   

About what I thought. I can do that. Is is possible (he asked hopefully) that there is a method in the LLBLGen code that will produce a 'standard' entity name from the passed in SQL table name, to which I can then add the 'Collection' or Entity' prefix?

stoneyowl avatar
stoneyowl
User
Posts: 62
Joined: 29-Jan-2004
# Posted on: 04-Nov-2005 18:57:24   

Well, now I get this....

Cannot apply indexing with [] to an expression of type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityCollection'

when I try to interate over the returned collection....

stoneyowl avatar
stoneyowl
User
Posts: 62
Joined: 29-Jan-2004
# Posted on: 04-Nov-2005 19:00:27   

Never mind - I solved it.