Traveling through tables

Posts   
 
    
bvalle
User
Posts: 54
Joined: 07-Jun-2006
# Posted on: 19-Mar-2007 21:29:29   

Hello

I need a way to travel through the tables without knowing their names. For example using the EntityType to find out all the tables and create collections to fetch data and go though the data.

Basically I am trying to read the database without hard coding all the tables and all the fields in the table at that time.

I know I can use the Fields collection (inside the entity) to travel through fields without knowing their names, but for the tables is there such a solution that I am not seeing?

Thank you, BV

LLBLGen Pro Version 2.0.0.0 Final Release 2/14/2007 .Net 2.0 Adapter

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Mar-2007 09:14:24   
bvalle
User
Posts: 54
Joined: 07-Jun-2006
# Posted on: 20-Mar-2007 21:27:19   

The article did help me in format some of the code correctly now.

My problem is now I have a way to create an IEntity2 from the EntityType enumeration, but I need to create a EntityCollection from the EntityType so I can pull all records from the tables one by one.

What am I missing here?


/// this does not work
IEntity2 entity = GeneralEntityFactory.Create(EntityType.AckTypeEntity);
EntityCollection entityCollection = new EntityCollection(entity);

/// neither does this
IEntity2 entity = GeneralEntityFactory.Create(EntityType.AckTypeEntity);
EntityCollection<entity> entityCollection = new EntityCollection<entity>();

I cannot type out the name of the tables because the database is in constant state of change. I do not want to have to have two points of entry (database and code). The main goal of this application is to generate code from tables.

Could you please point me in the right direction?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 21-Mar-2007 10:52:29   

If you don't know anything about the structure, how can you USE the objects in your application?

Btw, 'this doesn't work' isn't very helpful, please provide what kind of error you got from the compiler (or at runtime).

Frans Bouma | Lead developer LLBLGen Pro
bvalle
User
Posts: 54
Joined: 07-Jun-2006
# Posted on: 21-Mar-2007 14:37:27   

Ok, perhaps been vague is not helpful.

I am trying to create enumerations based on the tables. Some tables on my database have the following format:

refTableName xxxxID (int) xxxxName (string) xxxxDesc (string)

However not all tables have this format, but the ones that do I want to create an enumeration like this


enum TableName
{
   ///<summary>
   /// xxxxDesc
   ///</summary>
   xxxxName = xxxxID
}

So basically what my code needs to do is read all tables and look for the (ID,Name,Desc) pattern and from it use the data to create the enumerations.

My thinking was: - Use EntityType enumeration, which would tell me all the tables in the database. - From EntityType create EntityCollection - From EntityCollection I would be able to get the first record (if exists) and look at the fields and see if my (ID,Name,Desc) pattern exist - If it does exist then I would read the individual records and create enumerations.


/// Error 1 The best overloaded method match 
/// for 'InformationIntellect.DVM.Data.EnterpriseServer.HelperClasses.
/// EntityCollection.EntityCollection (SD.LLBLGen.Pro.ORMSupportClasses.IEntityFactory2)'
/// has some invalid arguments C:\DVMSystem\Version 2.0\Tools\EnumProject.cs

/// Error 2 Argument '1': cannot convert from 
/// 'SD.LLBLGen.Pro.ORMSupportClasses.IEntity2' 
/// to 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityFactory2'   
/// C:\DVMSystem\Version 2.0\InformationIntellect\Tools\EnumProject.cs

IEntity2 entity = GeneralEntityFactory.Create(EntityType.AckTypeEntity);
EntityCollection entityCollection = new EntityCollection(entity);
                                                            ^^^^^^^^^^1         ^^^2


/// Error 3 The type or namespace name 'entity2' could not be found (are you missing a 
/// using directive or an assembly reference?)  
/// C:\DVMSystem\Version 2.0\Tools\I2CodeGen\EnumProject.cs

/// Error 4 The type or namespace name 'entity2' could not be 
///found (are you missing a using directive or an assembly reference?)
///C:\DVMSystem\Version 2.0\Tools\I2CodeGen\EnumProject.cs

IEntity2 entity2 = GeneralEntityFactory.Create(EntityType.AckTypeEntity);
EntityCollection<entity2> entityCollection2 = new EntityCollection<entity2>();
                        ^^^^^^^3                                                                     ^^^^^4

Perhaps my approach is not the best, am I going to correct way?

Please let me know.

Thank you, BV

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Mar-2007 15:51:34   

Help us better understand your needs, maybe we can guide you to a better solution.

  • From EntityCollection I would be able to get the first record (if exists) and look at the fields and see if my (ID,Name,Desc) pattern exist
  • If it does exist then I would read the individual records and create enumerations.

What exactly will the enumurations include and what will use it for?

bvalle
User
Posts: 54
Joined: 07-Jun-2006
# Posted on: 21-Mar-2007 16:42:46   

The enumeration would be named after the table that records were pulled from. And the actual enum entries would be the records.

Basically these tables are my reference tables and all my data records are dependent to these reference tables.

For example a User table might have the following fields



UserTable
- UserID (int)
- UserName (string)
- Password (string)
- UserTypeID (foreign key)

UserTypeReference
- UserTypeID (int)
- UserTypeName (string)
- UserTypeDesc (string)

Now inside UserTypeReference I have the following records: 0,”LDAP”,”User account is held on the Domain Server” 1,”Local”,”User account is held on the local machine”

Therefore when I run my EnumGeneration I would get the following enum


enum UserTypeOption
{
   ///<summary>
   /// User account is held on the Domain Server
   ///</summary>
   LDAP = 0,
   ///<summary>
   /// User account is held on the local machine
   ///</summary>
   Local = 1
}

So on my code instead of checking for a record on the number I would use the enum to do it:

Example:


Public void IsLDAP()
{
   /// no need to compare against 0.
   return (UserEntity.UserTypeID == UserTypeOption.LDAP);

}

I would like to do a one point of modification for all enumerations

When someone create a new table or modifies the tables I can run LLBLGen against the database, recompile my code and run it. At the end I will have a nice set of enums that are based on the database reference tables. One point of modification, instead of having to add new entries to the database and then having to modify my enums.

Did this clear things up?

Let me know if you have any more questions.

Thank you, BV

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 22-Mar-2007 01:34:31   

There is a task performer in the customer section under 1.0.2005.1. It will allow you to generate a enum code file that is based on the contents of lookup tables in the database. Does that look like something you would need?