locked
Setting an Entity to be Read-Only RRS feed

  • Question

  • Is there a way to set that an entity is read-only based on a property that I define? For instance, if I have my own property called CanEdit, is there some way that RIA Services can mark the entity as read-only? Or do I just have to check my own property in the begin edit of the dataform?

    Thanks!

    Tuesday, September 1, 2009 8:03 PM

Answers

  • My understanding of the original question was that he was asking how to make a specific entity instance read only at runtime, not how to make a type of Entity read only.

    Exactly.

    I ended up just adding a property called Locked on my entity and then in the DataForm I use IsReadOnly={Binding Locked}, but it would be nice if I could override the IsReadOnly and put some of my own logic in there.

    Thanks!

    Wednesday, September 2, 2009 11:50 AM

All replies

  • You would need to override Entity.IsReadOnly to do that and IsReadOnly is not a virtual function. You can make sure an Entity is readonly until the next submit my calling a CustomMethod on it, any pending CustomMethod will mark the Entity as read only. However, when you submit that will clear the readonly.

    This is definitly an interesting scenario.

    Tuesday, September 1, 2009 11:19 PM
  • You could add the Attribute [ReadOnly(true)] to your property.

    Wednesday, September 2, 2009 2:16 AM
  • It would indeed be nice if you could decorate your entity data with UI-hints. Sure there is the "static" setup which makes a property read only for the entire entity set in memory. But there are also context aware settings. So for entity instance A the property Name is editable, but not for entity instance B. Deciding this is business logic, so it would make sense to generate it on the server when the client wants to know. On the other hand why would you generate this information, when the user is only browsing data. In the context of data entry it makes sense though.

    So besides "entity is read only" you could have "entity can be deleted". But you could also implement this optimistically and throw an exception when you want to delete an entity which is constrained. Difficult and interesting topic.

     

    Wednesday, September 2, 2009 4:34 AM
  •  My understanding of the original question was that he was asking how to make a specific entity instance read only at runtime, not how to make a type of Entity read only.

    It is a very interesting scenario, and the plumbing is pretty much there we just don't have any way of getting to it.

    Wednesday, September 2, 2009 9:55 AM
  • My understanding of the original question was that he was asking how to make a specific entity instance read only at runtime, not how to make a type of Entity read only.

    Exactly.

    I ended up just adding a property called Locked on my entity and then in the DataForm I use IsReadOnly={Binding Locked}, but it would be nice if I could override the IsReadOnly and put some of my own logic in there.

    Thanks!

    Wednesday, September 2, 2009 11:50 AM
  • My apologies, I should have re-read the question.  Glad you sorted it.

    Thursday, September 3, 2009 4:21 PM