0

Is there any way in code-first EF 5 to prevent updates on a specific entity/table? We are using EF in a WCF web service. We want updates to occur on one of the main objects, but not on some of the children.

The idea being that if we have a main object like this:

 class Person
 {
       public Address { get; set; }
       public string FirstName { get; set; }
       public string LastName { get; set; }
 }

 class Address
 {
       public string City { get; set; }
       public string State { get; set; }
 }

We would want changes to Person persisted, but not changes to Address.

Michael
  • 1,306
  • 1
  • 12
  • 30
  • Maybe this could help: http://stackoverflow.com/questions/5749110/readonly-properties-in-ef-4-1 – Allov Oct 18 '12 at 15:41
  • The main point of this is that we do not want UPDATE statements ever issued against a particular table. Would taking that route ensure that or just that the values never change? – Michael Oct 18 '12 at 18:00
  • Well, how I understand it is that for the "Person" object, a mapping will occur (read) but changes will never be updated (write) when saving the "Person" object. However, you would have to do the same for the "Address" object if you were to save it individualy. But, since you don't want to update it, ever, you won't be saving it, ever, too. Let me know if it's unclear. – Allov Oct 18 '12 at 18:39
  • I'm afraid it isn't quite clear. It is a true statement that I don't ever want to save `Address`. It is modified from a different service/domain entirely and must not be touched in this service. – Michael Oct 18 '12 at 20:21
  • If this is a WCF Data Service you should be able to set rights on entity sets. In EF you could override SaveChanges() and throw when an entity you want to be touched is marked as modified. – Pawel Oct 25 '12 at 04:17

0 Answers0