views:

38

answers:

1

I have a database table which records all field changes in all database tables which are mapped to Entity Framework Entities (via SQL Server triggers).

I am building a service which outputs these field changes to the client.

However, the client needs the EF-Entity object and property names and not the database table and field names.

For example, if these database fields change:

Table         Field        WhenChanged
------------  ------------ ----------          ...
Calendar      Event        2010-01-05 15:00:00
Calendar      Place        2010-01-05 15:22:00

I need to report that these entity properties changed:

Entity        Property        WhenChanged
------------  ------------ ----------              ...
Appointment   EventName        2010-01-05 15:00:00
Appointment   Place            2010-01-05 15:00:00

Some names are the same, some are not: the mapping is defined the .edmx file.

Are there any EF methods I can call or tools I could use which would do this backward tablename-to-objectname and fieldname-to-propertyname translation without actually instantiating the objects?

A: 

I'll say ahead of time I don't know much about the Entity Framework. However based on experience with other ORMs not sure what you want will work since you are dealing with the physical data not a mapping per se. So based on your example what you could do to solve your problem is have an entity that is mapped to your log file. Then when you send this log file down have it contain a lookup (dictionary) or use reflection to determine what goes where and then send that change down.

If you are just looking to do a name switch as in you just want to provide a running log of changes you could use the concept of a MetaData table that contains your entity / property mappings to table / field names. Then your sql could join to that table and pull back the associated name vs the database value.

Along the lines of the association / metadata route if you can parse your .edmx file you may be able to use that as your meta store and then just overlay the incoming values from the db based on that lookup.

Joshua Cauble