0

I am using BLToolkit and find out an interesting behaviour. I don't understand why using the same request in link give me different results: SQL request:


select TOP 1 * from table where  coverCode='1+4' 
                                             and effectiveDate <='20130103' 
                                              and  maxValue >= '1000'  
                                             order by maxValue asc, effectivedate desc

this table actually has two results:

  • A) (id): 1ffbe215-ff0e-47dd-9718-4130ffb62539 (maxValue): 1000 (effDate):2011-01-01 (price):40

  • B) (id): b787a74e-696b-493d-a4bc-5bb407e231b3 (maxValue):1000 (effDate):2011-01-01 (price):80

and SQL request gives me the A result. and at the same time the request using Linq:

db.Rate
   .Where(x=>x.coverCode == "1+4"
           && x.effectiveDate <= '20130103'
            && x.MaxValue >= '1000')
            .OrderBy(x => x.MaxValue)
            .ThenByDescending(x => x.effectiveDate)

This request gives me the B result. Can anyone explain why or what is wrong in the linq request?

user1706449
  • 159
  • 1
  • 1
  • 9
  • The LINQ code would not compile. Please show us the actual code that you executed. – usr Jan 03 '13 at 14:25
  • Also, please post the generated SQL which you can catch by running SQL Profiler. – usr Jan 03 '13 at 14:26

1 Answers1

1

You may want to inspect your db.LastQuery right after your LINQ code executed. You'll see the generated SQL, and you can compare it with the one you really wanted.

andri
  • 1,021
  • 1
  • 9
  • 16