Graeme
Graeme

Reputation: 2687

How to create read-only entity in Entity Framework?

My app is purely read-only so I don't want to generate all the update & delete code, and I don't want to pull in all fields from all tables. Some of these fields are not nullable so I am getting errors from EF here becasue there is no default value to save.

In my previous ORM (Wilson) you could just flag an entity as read-only in the XML. I've seen a few posts showing convoluted solutions to this. Am I missing something? Why isn't this straight forward?

I see that the RIA services wizard has a check box for this for each entity...

Upvotes: 8

Views: 1756

Answers (1)

Craig Stuntz
Craig Stuntz

Reputation: 126547

The problem is that you have a non-nullable field in your SSDL which isn't in your CSDL.

You can manually remove the column from SSDL and the EF will be happy. But the designer will re-add the column when you update the model. So you can either remove it again or update your model from a variant of the DB which doesn't have that column.

Upvotes: 1

Related Questions