GetChanges if collection Is Managed

2 posts, 0 answers
  1. Florian
    Florian avatar
    2 posts
    Member since:
    Jan 2015

    Posted 13 Jan 2015 Link to this post

    Hi there

    I have the following problem: I inherit the OpenAccessContext to add entries into history tables upon saving changes (slowly changing dimensions, type 4). Everytime a entity gets updated, I write an entry into a corresponding history table. For this I use the method "GetChanges().GetInserts/GetUpdates" of DataAccess.
    I.e. if we update the "LastName" property of entity "Person", an entry to "HistPerson" will be written.

    This has worked so far very well until I changed the collections on "Person" to IsManaged = true. Since then, I receive "false positives" when calling GetChanges on the context. I.e. if I change a persons "Diploma", also the parent "Person" (Diploma.Person) is marked as dirty (altough there are absolutely no changes - only the Diplomas-collection has an additional entry...).
    I don't know if this is by design or a bug. If it's by design, I need a way to filter out the unchanged parents.

    My ERD:
    Person  1 <-> * Diplomas
    Person  1 <-> * Licences
    Licence 1 <-> * Addresses
    Licence 1 <-> * Restrictions

    Do you have any suggestions how to solve/workaround this problem? Are there possibilities to get the changes on a "per field" base (so then I can filter out the TrackedLists myself)?

    Greetings,

    Florian
  2. Kaloyan Nikolov
    Admin
    Kaloyan Nikolov avatar
    118 posts

    Posted 16 Jan 2015 Link to this post

    Hi Florian,

    The GetChanges<T>() method operate on Object level which means that it detects changes in the modified entities even they don't cause any SQL update/delete/insert statements to be executed. The reason why you see those false changes is that when the references are managed Data Access adds/removes the entities from the respective collections and thus touches the entity. Unfortunately there is not way to detect whether those changes are because the navigational properties are updated or some of the data properties are updated. 

    If you can work without the managed collections then the GetChanges() method will work for your scenario.

    Should you have any other questions do not hesitate to get back to us. 

    Regards,
    Kaloyan Nikolov
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
  3. DevCraft banner
Back to Top