OpenAccessContext.Events.Changed problem with entity navigation properties

Thread is closed for posting
2 posts, 0 answers
  1. Yijun
    Yijun avatar
    5 posts
    Member since:
    Feb 2013

    Posted 15 Mar 2016 Link to this post


    I have an application that has to do Audit trail for all db changes.

    I am listening to the OpenAccessContext.Events.Changed and then collecting the changes made to generate an audit record.  The problem I'm having is that my Audit Entity is related to a User entity, therefore,  the User entity has a list of Audits as a navigation property.  When I add the new Audit record to the context, a Changed event is raised for the User object saying that the Audits property changed.  When this event is raised, a select query to the database is automatically done by telerik and it retrieves all the Audit records for that User.  As the user perform more operations, every submit operation in the system slows down more and more.  We have new users that take around 2 secs for the same operation that old users take 3 minutes.  I was not easy to find out that this was happening.  I had to use the Profiling and Tuning advisor to find the issue.  Is there a way to work around this???

  2. Kaloyan Nikolov
    Kaloyan Nikolov avatar
    118 posts

    Posted 23 Mar 2016 Link to this post

    Hi Yijun,

    I think the issue you face could be side effect of one of the following things:

    1. Most probably the association between Audit and User is set to IsManaged = true. As result Telerik Data Access will load the Audits collection fully when you try to add an entity in it. That could be the reason of the queries you observe. I suggest you to remove the IsManaged() call in your fluent mapping for this association.

    2. It could be caused by a custom code that tries to reach all properties and thus the navigation property Audits gets loaded. 

    If non of the above help you then you could consider braking the physical association between both entities and manage it logically in your code. 

    I hope this information will help you to identify the root case. 

    Kaloyan Nikolov
    Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Back to Top