locked
Change tracking with POCO proxies RRS feed

  • Question

  • I have a few template-generated POCO (non-STE) objects with proxies that I am adding some extra properties to in partial classes and I have a couple questions:

    -When is the proxy smart enough to requery if another request/user changes its navigation property's backing data in the DB?

    -If all properties have automatic getter and setters and LazyLoading is enabled, the framework will take care of change tracking and everything is dandy, right?

    -I want to add a public property with no backing member that only has a getter (and is dependent on a navigation property's child collection), will this work automatically?

    -What if I use a private member and a public property?

    -Is there any reason I should have to explicitly call DetectChanges?

     

    Thanks.

    Monday, July 11, 2011 5:14 PM

Answers

  • Hello,

    1. Proxy never requery itself. Even manual requerying requires forcing the entity to be refreshed with data in the database. Change tracking has nothing to do with changes done in database. It only tracks changes done to current instance in the application.
    2. Properties must be also virtual (lazy loading is not needed) and entity must be attached to live context.
    3. If this property is in your partial part, it is not part of your model and it doesn't break anything.
    4. Again if this is in your private part it is up to you. Property which is mapped cannot have private member. It can only have changed accessibility for getter or setter (configured in EDMX).
    5. If you have automatic change tracking you don't need it.

    Best regards,
    Ladislav

    • Marked as answer by Alan_chen Tuesday, July 26, 2011 5:53 AM
    Tuesday, July 12, 2011 11:44 AM

All replies

  • Hello,

    1. Proxy never requery itself. Even manual requerying requires forcing the entity to be refreshed with data in the database. Change tracking has nothing to do with changes done in database. It only tracks changes done to current instance in the application.
    2. Properties must be also virtual (lazy loading is not needed) and entity must be attached to live context.
    3. If this property is in your partial part, it is not part of your model and it doesn't break anything.
    4. Again if this is in your private part it is up to you. Property which is mapped cannot have private member. It can only have changed accessibility for getter or setter (configured in EDMX).
    5. If you have automatic change tracking you don't need it.

    Best regards,
    Ladislav

    • Marked as answer by Alan_chen Tuesday, July 26, 2011 5:53 AM
    Tuesday, July 12, 2011 11:44 AM
  • Hi j-simms,

    I am writing to check the status of the issue on your side. Would you mind letting us know the result of the suggestions?

    If you need further assistance, please feel free to let me know. I will be more than happy to be of assistance.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, July 18, 2011 3:56 AM