5

I was first using LINQ to SQL in my project and used the following statement:

var ProjectRouteEmails = EmailManagerDAL.Context.ProjectRouteEmails
            .Where(p => p.ProjectID == ProjectID);

That correctly returned the three distinct emails from the view ProjectRouteEmails. The IDs returned from the Emails table were 117, 591, and 610.

I changed to LINQ to Entities and use the same view and same LINQ statement, but even though I am getting back three records, it is the first record, ID 117, that is getting returned three times.

I tried writing the LINQ statment like this:

var ProjectRouteEmails = from p in EmailManagerDAL.Context.ProjectRouteEmails
                                 where p.ProjectID == ProjectID
                                 select p;

but it made no difference; the same record returned three times.

I went into SQL Server Management Studio and ran the query:

select * from ProjectRouteEmails (nolock) 
where ProjectID = 12

and the correct three, unique records returned.

What is going on here?

Thanks!

2
  • I would double check how you're iterating through this to output... sounds fishy Commented May 10, 2011 at 13:19
  • I am just binding it to a Grid. Also I have a breakpoint set and examining it in the watch window shows the same results. Commented May 10, 2011 at 13:24

1 Answer 1

5

Make sure the entity key is set correctly for ProjectRouteEmails in the Entity Data Model. Sometimes the entity keys are messed up when you import the view into the model.

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

3 Comments

Interesting...can you provide specifics or more detail? Is it in the entity object? Or...some relational metadata? Some may use the tools to create the entity data model without digging into the nuts & bolts.
THAT WAS IT!!!! Thank you Aducci! It seemed to have arbitrarily selected a text field as the entity key. I changed it to the correct field and it works. Thank you!
Just for future reference for others. Open the edmx then your view right click on the field and add entity key.

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.