Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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...

like image 285
Graeme Avatar asked Jan 28 '11 13:01

Graeme


1 Answers

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.

like image 191
Craig Stuntz Avatar answered Nov 02 '22 11:11

Craig Stuntz