Entity Framework: Dealing with views with no primary key

In entity framework there was a known issues or views with no primary will returns all the duplicated rows, because it couldn’t identity what’s different in the rows without a primary key.

There is a quick code fix we can apply to that,

Instead of using context.viewTest.toList(), we use the following:

In EF 5:

context.Database.SQLQuery<viewTest>(“Select * from viewTest”);

In EF 4:

context.ExecuteStoreQuery<viewTest>(“Select * from viewTest”);