views:

295

answers:

1

Right... calling all Entity Framework experts...

I have a table called Bob in my database, my EF model contains an exact mapping/definition of this. I also have a table called Jim who is also mapped to my entity model. Bob can have multiple Jim's and this relationship is enforced by foreign key constraints as it should be. So the relationship here is rosey. However, I also have created my own entity in my EF model called JimSnapshot. This entity looks exactly the same as the Jim entity. When Bob is created, a snapshot of Jim is taken at that point and stored as very flat XML in a column called JimSnapshotXML in Bob.

What I want to do is have the JimSnapshot entity related to Bob and infact replace the JimSnapshotXML property with a populated version of the JimSnapshot entity. Or at least have the JimSnapshot entity accessible from Bob and the JimSnapshotXML attribute hidden.

Is this possible? How can I do it? Does any of this make sense?

Essentially I am aiming to be able to access the above as follows (C#);

var snapshot = Bob.JimSnapshot;
var jim = Bob.Jim;
A: 

You can try to create a wrapper property in the partial class extending the entity code that will create an instance of the JimSnapshot in getter and write the correct XML in setter.
However, there will be troubles with change tracking, you'll have to assign this property explicitly or to handle the SavingChanges event to save the changes to the XML.

Devart
Excellent. Thank you. Could you elaborate a little more to help point me in the correct direction?Much appreciated.
Carl