I need to get the current context given an entity
I found this old article from 2009
given that we’re now firmly in 2012, is there another way ?
UPDATE – here are some details on where this is reqd
Table1 – at the heart of the star shaped schema
Tags nvarchar(300)
Idx identity int
Table2 – Tags reference
TagID identity int
TagText nvarchar(50)
Table3 – Rel between Table1 & Table2
IDX FK
TagID FK
In the Context.SavingChanges() event for Table1
the tags are parsed and saved to Table2 with the relationships added to Table3 using context from Table1
Any guidance on how to improve this are welcome
If you are in the SavingChanges event handler, then you don’t need to get the context from the entity, but rather the sender object of the event is the ObjectContext. This is the appropriate place to get the context in such a scenario. For example: