Click here to Skip to main content
15,891,747 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on a project using SQL Azure. In order to handle Sql Azure Transient Errors I am using Transient Fault handling framework.

I have a class MContext which inherits from DbContext I wrote a method override for entity framework SaveChanges() method in this class as below:

C#
private ITransientErrorDetectionStrategy errorDetectionStrategy = new SqlAzureTransientErrorDetectionStrategy();

private RetryPolicy policy= new RetryPolicy(errorDetectionStrategy, 3);

 public override int SaveChanges()
        {
            return policy.ExecuteAction(() =>
            {
                return base.SaveChanges();
            });
        }  


This way I don't have to make code changes throughout my project where ever SaveChanges() is called.

I want to know if there is a way to do the same for LINQ queries.

For example:

C#
policy.ExecuteAction(() =>
            {
                var x = from user in context.Users select user.Id;
            });


Instead of making code changes throughout the project by adding the

C#
policy.ExecuteAction(() =>
            {
}); 


block for all the linq queries and enforcing others in the team to do the same, is there a way to intercept the linq query within the MContext class and apply the Transient handling?

I can write an extension method and call it on all the queries, but again that would require code change throughout the project.

I want to handle it in one place just like overriding the SaveChanges() method and not make changes all over the project.

Thanks for your help!
Mahesh
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900