question table schema

Posts   
 
    
frankchen
User
Posts: 7
Joined: 16-Nov-2007
# Posted on: 04-Apr-2008 21:15:24   

Hi,

I got requirement to develop a weakly type webservice to provide interface for multiple application to access database. One of interface I defined as following.

public DataTable Query(string tableName, string[] fields)
{
}

I have to validate whether parameter is valid base on database schema. For example, check table of tableName is existing on database. check field in fields list is valid in table. So, I just want to know whether LLBLGen Pro 2.5 has curtain funtions to map between real table and table entity.

BTW, I know I can use following code to get column list and real table name based on the entity. But how can I get entity based on table name?

IPersistenceInfoProvider info = PersistenceInfoProviderSingleton.GetInstance();
IFieldPersistenceInfo[] fieldInfos = info.GetAllFieldPersistenceInfos(new TableEntity());
foreach (IFieldPersistenceInfo item in fieldInfos)
    Console.WriteLine(String.Format("Table {0} Column {1};",item.SourceObjectName, item.SourceColumnName ));
goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 05-Apr-2008 20:53:16   
frankchen
User
Posts: 7
Joined: 16-Nov-2007
# Posted on: 07-Apr-2008 19:24:28   

goose wrote:

this thread might be useful:

http://llblgen.com/tinyforum/Messages.aspx?ThreadID=4594

Hi,

Thanks for your reply. I think reflection is the way to work that, but not best way to work that. think about if I have more than 100 tables, I need to create mapping information between table name and entity name from webservice point of view. Any new table or delete table happen, I have to update mapping. That sounds not efficient.

I also found that table and column information are added into PersistenceInfoProviderCore class. Is it possible to get IEntityFactory2 from PersistenceInfoProviderCore class?

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 08-Apr-2008 09:47:59   

Instead of using the tableName, you might need to use the EntityType enum, to be able to use the Activator.CreateInstance() method.

public DataTable Query(Type entityType, string fieldName)
{
    IEntity2 EntityObj = (IEntity2) Activator.CreateInstance(entityType);
}