Reputation: 13
I'm using entity framework in VS2010 .NET 3.5 to expose a stored procuedure. The results in VS are incorrect, but the result manually executing the stored procedure look good. For example:
Here is the sp that returns only the distinct names based on a search string using LIKE:
SELECT Name,GETDATE() AS Date FROM
(SELECT DISTINCT Name FROM Customers WHERE Name LIKE 'br') dt_result
When executed from Query Analyzer in SQL Mgt Studio results look correct:
Name Date
Brian 2011-12-01 10:59:40.093
Brady 2011-12-01 10:59:40.093
Bryan 2011-12-01 10:59:40.093
My code to expose the results of the stored procuedure in VS looks like this:
var results = (from i in dbentities.SearchName('br')
select i).ToList();
But results contains this:
Name Date
Brian 2011-12-01 10:59:40.093
Brian 2011-12-01 10:59:40.093
Brian 2011-12-01 10:59:40.093
The number of entities is correct but the property contain the same value. Any ideas why this might be happening?
Thanks in advance.
Upvotes: 1
Views: 176
Reputation: 131
Your keys on the Entity are probably not unique. This little bug has caught me multiple times when returning results from stored procedures into entities.
To fix it simply go into your Entity model remove the existing keys on the entity and ensure the new key you pick is unique.
Hopefully this helps.
Upvotes: 1