This is a migrated thread and some comments may be shown as answers.

OpenAccessContext.Events.Changed problem with entity navigation properties

1 Answer 27 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Yijun
Top achievements
Rank 1
Yijun asked on 15 Mar 2016, 02:58 PM

Hello,

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???

1 Answer, 1 is accepted

Sort by
0
Kaloyan Nikolov
Telerik team
answered on 23 Mar 2016, 08:16 AM
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. 

Regards,
Kaloyan Nikolov
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Tags
Development (API, general questions)
Asked by
Yijun
Top achievements
Rank 1
Answers by
Kaloyan Nikolov
Telerik team
Share this question
or