Retrive column name at Runtime

Retrive column name at Runtime

Postby JoeRuspante » Mon 12 Mar 2012 23:28

Hi.
In Model First environment, there is any way to know at runtime what Table/column a property is mapped to?

For example, if the property User.Name is mapped to "TBL_USER"."PROP_NAME" on the DB, how can I have this information at runtime?


I need that because I'd like to write a log of every change a user will do in any property of any table.
But I'd like to use the table/column names instead of Classes/Properties names.


Someone can help me?
Thank you in advance.
JoeRuspante
 
Posts: 54
Joined: Mon 05 Jul 2010 23:08

Postby Shalex » Thu 15 Mar 2012 08:34

You can easily set the corresponding naming rules in Entity Developer so that mapping was done in the following way: the name of the class is equal to the name of the table, the name of the property is equal to the name of the column.
Shalex
Devart Team
 
Posts: 7527
Joined: Thu 14 Aug 2008 12:44

Postby JoeRuspante » Sun 18 Mar 2012 09:27

Thank you, but I need to have different name between classes and tables.

For example, the "User" class is mapped in the DB as "SYS_UTENTI".
This is because we would like to set special names for some tables (SYS for the system one) that we doesn't like to appear on the model.

The first way I thought is to read the XML generated by the model (the mapping one), but I hope there is a simpler method using the reflection or the DbModel that already read that mapping file.
JoeRuspante
 
Posts: 54
Joined: Mon 05 Jul 2010 23:08

Postby Shalex » Wed 21 Mar 2012 17:14

This question rather should be addressed to the Microsoft team.

It seems like all DbContext's mappings are internal and cannot be easily/conveniently retrieved. Probably, the easiest and quickest solution would be setting attributes with mapping to properties. Are you using Entity Developer? If yes, you can modify the code-generation template by adding generation of attritutes for properties with specifying the column name.
Shalex
Devart Team
 
Posts: 7527
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for Oracle