Reputation: 201
My LINQ query is returning some strange results.
LINQ Query (returns incorrect results):
IEnumerable<PART_EVENTS> parts = db.PART_EVENTS
.Where(p => p.OP == op.NCM_DB_NAME && p.Timestamp > tempBegin && p.Timestamp <= tempEnd)
.OrderBy(p => p.PART_ID_NUM)
.ThenBy(p => p.Timestamp)
.ToList();
The results returned in the Visual Studio debugger show the same Timestamp for each unique Part ID, but a direct query in SQL Developer or the Query window (in Server Explorer) shows different timestamps (indeed, the timestamps for each row should be different.)
SQL Query (returns the correct results):
select *
from PART_EVENTS
where OP = 'OP20B'
AND "Timestamp" > to_date('11/28/2012 07:00 am', 'mm/dd/yyyy hh:mi am')
AND "Timestamp" <= to_date('11/28/2012 10:58 am', 'mm/dd/yyyy hh:mi am')
order by part_id_num, "Timestamp"
I've tried many things to try to correct this and have been at this for 2 days, but I don't know what I am doing wrong or if there is something wrong with the SQL being generated by EF.
Any advise would be greatly appreciated. Thank you.
Upvotes: 1
Views: 401
Reputation: 201
Just before posting my question, I decided to try one more thing: Change the "Timestamp" alias to PART_TIMESTAMP. Apparently LINQ doesn't like the quoted alias. This fixed the problem.
Upvotes: 1