none
Is virtual property no longer a requirement for change tracking? RRS feed

  • Question

  • The documentation for 4.1 says that POCO properties must be virtual (Overridable) to get change tracking. The entity classes that were created only had "Overridable" on the navigational properties and yet I still got change tracking( I verified this) .

    So I take it that this is no longer a requirement? Shouldn't you change the documentation?

    Friday, September 30, 2011 8:44 PM

Answers

  • I'm sorry I didn't make my self clear. I realize now that my test for auto change tracking was flawed. I then wondered why the text generating file was not generating all virtual properties. The fact that it doesn't is what led me to believe it wasn't necessary. I realize now that it is necessary.   

    Sorry about the confusion. 

    • Marked as answer by DavidSherwood Saturday, October 8, 2011 6:20 AM
    Saturday, October 8, 2011 6:20 AM

All replies

  • Hi,

    How have you checked this ? See http://msdn.microsoft.com/en-us/library/gg696177(v=VS.103).aspx. This is a requirement for "instant" tracking but if not met, it can still fallback to the "snapshot based" tracking.

    Your best bet is likely to show us the smallest sample of code that would show that behavior (and in particular see the note that explains when DetectChanges is called, IMO this is more likely what happens)...


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    Saturday, October 1, 2011 9:39 AM
  • In my test code I fetched the entry for the entity after I changed the property. Does this call DetectChanges?  When I changed the code to fetch before I make the change and check after, it still shows Unchanged.

    So I guess my next question is why isn't the text generating file generating "Overridable"? Is there a way to tell it to?

    Saturday, October 1, 2011 11:25 PM
  • So I guess my next question is why isn't the text generating file generating "Overridable"? Is there a way to tell it to?

    What's the meaning of text generating file generating overridable? did you point it .tt file or others? I think you have to describe your question more detail.

    Thanks,

    Werewolf,


    Just a newbie for everything.
    Tuesday, October 4, 2011 5:48 AM
  • Sorry, Overridable is VB speak for virtual. I did find in the text file why it wasn't. It didn't wrap the Accessibility for primitive properties with PropertyAccessibilityAndVirtal. So only the navigation properties became virtual
     
    Wednesday, October 5, 2011 6:38 PM
  • The note I was talking about was :

    "When working with the DbContext API, the Entity Framework calls the DetectChanges method automatically when the following members are called:

    I'm not sure what you mean with your other code (what means "check", it's better to see some code rather than "describing"' what you  code does).

    IMO it could be better to restart from the beginning. Do you generate Code First POCO classes using the reverse engineering option ? It should work even without override as this is not a requirement but it uses another fallback option. If you want still to force using this change tracking method you can always copy and change the default template.

     

     


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
    Thursday, October 6, 2011 9:59 AM
  • I'm sorry I didn't make my self clear. I realize now that my test for auto change tracking was flawed. I then wondered why the text generating file was not generating all virtual properties. The fact that it doesn't is what led me to believe it wasn't necessary. I realize now that it is necessary.   

    Sorry about the confusion. 

    • Marked as answer by DavidSherwood Saturday, October 8, 2011 6:20 AM
    Saturday, October 8, 2011 6:20 AM