Problem with conversion of linq query to sql

Thread is closed for posting
2 posts, 0 answers
  1. test
    test avatar
    27 posts
    Member since:
    Feb 2008

    Posted 06 Jun 2012 Link to this post


    I've a problem with a linq query that it's not well converted in sql query. The problem concern parentheses that are not correctly translated in my SQL query.

    Here's my linq query :

    (from p in this.DbContext.PriceAgreements
    where ((p.ItemRelationType == 0 && p.ItemRelationCode == ItemCode) || (p.ItemRelationType == 2 && p.ItemRelationCode == ""))
    select p).ToList();

    Here's the resulting sql query in trace file :

    SELECT ....
    FROM [PriceAgreement] a WHERE (a.[ItemRelationType] = 0 AND a.[ItemRelationCode] = @p0 OR a.[ItemRelationType] = 2 AND a.[ItemRelationCode] = '') ORDER BY COL1

    As you can see the parentheses are not well translated.

    I use 2012.1.301 version of Open Access.

    Thanks for your help.
  2. Thomas
    Thomas avatar
    590 posts

    Posted 06 Jun 2012 Link to this post

    Operator precedence allows to formulate the query without brackets. This is what's happening here.
    Please see here for a list of those operator evaluation rules. As * has precedence over +, so does AND over OR.

    Kind regards,
    the Telerik team
    Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
Back to Top