Field Alias Name

Posts   
 
    
Emerald
User
Posts: 5
Joined: 01-Aug-2006
# Posted on: 01-Aug-2006 17:02:24   

Hello,

I am evaluating the latest release of LLBLGen for my company. One of the tasks I have is to generate metadata about the entities. I have been using Oracle 9i database, with .NET 2.0 and generated the code using the Adapter Scenario.

I ran into a problem while fetching some information about EntityFields that have been aliased in the designer.

For example, in the Customer Entity the id field in the database is called 'ID' and it has been aliased as 'CustomerID' in the designer. Now, when I am trying to retrieve the persistenceInformation using the following lines of code

IFieldPersistenceInfo[] persistenceInfo = GetFieldPersistenceInfos(_Entity); for() { dataRow["SourceColumnName"] = persistenceInfo[i].SourceColumnName; ...... ...... }

This returns the actual database field name which is 'ID'

Additionally,

I am using the following code to retrieve the primary key or foreign key information List<IEntityField2> keyFields = _Entity.Fields; The name and alias generated by the following line is "CustomerID" which is the Alias. for() { dataRow["PropertyName"] = keyFields[i].Name; }

Is there some how I can match up this information?

Thanks in Advance.

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 01-Aug-2006 17:28:29   

Hi,

You have to understand that adapter scenario seperates the generic entities you generated from the specific db bindings you plug to them.

That allows to have the same set of entities hydrate different dbs, from different dbms (some people actually use that functionality to provide multi-dbms support in their apps).

Accordingly, everything you get from your generic entities, such as the "Fields" lookup array, corresponds to your project settings independently from the db behind it.

Then everything you get from the dbspecific PersistenceInfoProvider in your dbspecific project corresponds to the db implementation you plug behind.

The matching between them is done in the PersistenceInfoProvider where the table data are stored by the name of their entities, and the column specs both by the index of the corresponding entity field and by its name.

So when you create a query by manipulating the generic objects, the dataccessadapter you use to perform the query is responsible for making it a specific query, turning the entities and fields into their corresponding Tables and columns by calling its singleton PersistenceInfoProvider, and by instanciating the Dynamic Query engine corresponding to the correct dbms.

basically, that means that within two lines of code you could have two different DataAccessAdapter run the same query on two different dbs by passing them the same generic arguments.

Hope I made it clearer.

Emerald
User
Posts: 5
Joined: 01-Aug-2006
# Posted on: 01-Aug-2006 17:41:45   

Thanks for the quick response.

Yes, I do understand what you are getting at. So, is there anyway I could get the elementFieldName from the PersistenceInfoProvider?

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 01-Aug-2006 20:28:51   

Well, the PersistenceInfoProvider was mainly conceived to get the persistence info corresponding to the generic entities, so you should use it in that direction.

First you have to get rid of the "Friend" accessibility, which you seem to have done considering your code.

Then, for instance you can browse your entities and corresponding entity fields, and for each one of them you can call the GetFieldPersistenceInfo( string elementName, string fieldName ) which will get you the corresponding dbbindings.

Otherwise, if you wish to call the GetAllFieldPersistenceInfos(...), it gets you and array of IFieldPersistenceInfo with elements in the same order as the entity fields enum from the ConstantsEnums file, which is also the order you have them in the _entity.Fields property.

But then the IFieldPersistenceInfo data item itself only contains the definition from the dbase column, it does not contain the mapping back to the field it is associated to. The mappings are done in the dictionaries of the PersistenceInfoProvider, which index the persistencedata by both the corresponding field names and their indices.

Emerald
User
Posts: 5
Joined: 01-Aug-2006
# Posted on: 02-Aug-2006 15:44:02   

Thanks for your help. That saved a lot of time.