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”);


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s