views:

18

answers:

1

Hi guys.. I'm using EF4. I've found a very annoying issue.

I have a db view that I've dragged into my Entity Model class. When I try to iterate over the hole collection, the data displayed, it's almost the same that the first objects... I've tried enabling Lazy Loading, but nothing works.. it's a really simple snippet.. why doesn't work???

Dal.Entities context = new Dal.Entities();                
list = context.vw_Full_Poll.ToList();

foreach (var item in list)
                {
                    PrintPoll(htmlWriter, item);
                }
A: 

You haven't defined a PK for the view. Since DB VIEWs don't have PKs, the EF can't derive this automatically.

Craig Stuntz
By "almost the same that the first objects" I meant that for example, the hole data contains about 5000 rows, and when I printed these rows, the data displayed is the same for the row #1,#2,#3...
When I said, nothing works, I meant that by enabling Lazy Loading, the result is the same... the printed data corresponds to the #1-#10 rows printed many times as rows returned the DAO method.
Ok!!! worked!! Thanks! It's a little strange cause using old "ADO disconnected mode", foreach funcionality worked just fine... but also, makes sense, that EF possibily isn't able to find which record is different from another without a PK. Thanks again