home | articles | site map | contacts
about us
consulting
client login
support
contacts



  Fixing: DbLinq Slow MySql Queries, Linq to SQL
Primary Objects C# .NET RSS Feed More C# ASP .NET
Articles by Primary Objects
enter email address
  

The following is a fix for an issue with slow queries in DbLinq when using MySql. The problem causes very slow MySQL queries when using LINQ to SQL with DbLinq, and displays a list of ArgumentExceptions, thrown before the query is executed. The query can take up to 8-10 seconds to execute.

Here is a work-around fix for the issue:
Download SVN patch 1
Download SVN patch 2

1. Download the latest SVN code for DbLinq at
http://code.google.com/p/dblinq2007/source/checkout

2. Open the following file for editing in Visual Studio 2008 DBLinq\src\DbLinq\Data\Linq\Sugar\Implementation\ExpressionOptimizer.cs

3. On line 78, the problem manifests itself when attempting to evaluate the lambda expression. Change the function AnalyzeConstant() as follows:

        protected virtual Expression AnalyzeConstant(Expression
expression, BuilderContext builderContext)
        {
            // we try to find a non-constant operand, and if we do, we
won't change this expression
            foreach (var operand in expression.GetOperands())
            {
                if (!(operand is ConstantExpression))
                    return expression;
            }
            // now, we just simply return a constant with new value
// ***** COMMENTED OUT CODE *****
            /*try
            {
                var optimizedExpression = Expression.Constant
(expression.Evaluate());
                // sometimes, optimizing an expression changes its
type, and we just can't allow this.
                if (optimizedExpression.Type == expression.Type)
                    return optimizedExpression;
            }
                // if we fail to evaluate the expression, then just
return it
            catch (ArgumentException) { }*/
// ***** END COMMENTED OUT CODE *****//

            return expression;
        }

4. Re-compile the DbLinq project to get the new DbLinq.dll and reference it in your projects. The ArgumentExceptions should no longer appear and queries are executed instantly. 

  Post comment >
        
DateUserComment
   No comments yet, you can be the first.

Profile
Learn more about Primary Objects and our goals ..  More
06/15/2010
Primary Objects publishes Linquify for .NET developers, on CodePlex .. More
12/22/2009
Primary Objects releases Linquify for .NET developers, LINQ to SQL library .. More
Home | About Us | Services | Client Login | Job Opportunities | Contact Us
Copyright © Primary Objects 2009
Privacy Policy
Follow us on Twitter