Reputation: 11
I have a situation and I don´t understand. The case is very simple. I use the a generic repository to work my DB. http://efgenericrepository.codeplex.com/ All work very well, but now just 1 view I get a problem. I think the EF return a word data when I execute a query.
this is my SQL result in SQL Manager:
Select *
from Vw_HoursMOPJustificated
where IdUser = 20
and ActionDate = '2012-08-22' and Hour < 24
IdMopTime | IdJustification | IdJustificationType
44 30 8
44 40 11
44 43 13
45 31 8
45 41 12
46 32 8
And this is my result inside C# when I execute this simple code.
MyIGFEntities entity = new MyIGFEntities();
var table = new Repository<MyIGF.Models.Vw_HoursMOPJustificated>(new MyIGFEntities())
.Find(x => x.ActionDate == ActionDate && x.IdUser == IdUser && x.Hour < 24);
IdMopTime | IdJustification | IdJustificationType
44 | 30 | 8
44 | 30 | 8
44 | 30 | 8
45 | 31 | 8
45 | 31 | 8
46 | 32 | 8
Anybody can Help me?
Upvotes: 1
Views: 74
Reputation: 60503
You must correct your edmx (quite sure you have one).
On your Vw_HoursMOPJustificated entity and set Primary Key to true for IdMopTime, IdJustification and IdJustificationType (at least).
To check if everything is correct, try to get data from your edmx, and see if you have correct distinct data.
Sometimes (and mainly with views, which don't have a "real" primary key in db), the primary keys (or the properties which makes each row distinct) are badly retrieved, and you get this kind of confusing results.
Upvotes: 1