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.
Retrive column name at Runtime
-
- Posts: 54
- Joined: Mon 05 Jul 2010 23:08
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.
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.
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.
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.