Entity Framework and View

Entity Framework is a really useful way for .NET developers to interact with databases. Recently, I have been working on implementing oData using WCF(Windows Communication Foundation).

A quick overview on oData:

Since, data in the data warehouse contains sensitive and too much details. It is necessary in this case to create a small subset of data using View. The fun begins with Entity Framework seems to have issues when creating and updating the data structure. Common errors are:

“1. The table/view TABLE_NAME does not have a primary key defined and no valid primary key could be inferred. This table/view has been excluded. To use the entity, you will need to review your schema, add the correct keys, and uncomment it”

This can be resolved easily. For example, if you Table Primary Key column is “ID”, in your View, you have to add this code, ISNULL(ID, – 1) AS ID.

2. Unable to update the EMDX – View mapping errors.

This is a little bit more complicated and workaround is found by manually editing the EMDX file using the XML Editor.

  1. Remove the <DefiningQuery>…<DefiningQuery>
  2. Remove store:Name=”XXXX” attribute from the <EntitySet> tag
  3. Remove the store prefix from the store:Schema attribute in the <EntitySet>

Now you can update your model again.


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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

%d bloggers like this: