1

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I had written up entire question and before submitting the question, I thought I would try one more thing. Since that worked and I had already written the question, I thought I would share my answer. The "Ask a Question" form even has a section for answering your own question, so I didn't think there would be anything wrong with doing that. I thought maybe I would save someone else some trouble later on if they were searching and found my solution. Is there something wrong with what I did?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.