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

Problem with conversion of linq query to sql

1 Answer 68 Views
LINQ (LINQ specific 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.
test
Top achievements
Rank 1
test asked on 06 Jun 2012, 08:46 AM
Hi,

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.

1 Answer, 1 is accepted

Sort by
0
Thomas
Telerik team
answered on 06 Jun 2012, 10:21 AM
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,
Thomas
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!
Tags
LINQ (LINQ specific questions)
Asked by
test
Top achievements
Rank 1
Answers by
Thomas
Telerik team
Share this question
or