views:

10

answers:

2

We have an Entity Framework model that is used by two different silverlight applications. The validation rules are very similar in the two contexts, but differ slightly.

For example, a regular user in one of the applications cannot input time that is in the future, but an administrator in the other application can put time that is in the future.

How would you handle designing this application? Two ideas we came up with:

  1. Creating two entirely separate models, so that each can be independent
  2. Share the same model, but put a "Context" property on our base Entity class, so that the validation rules can validate differently where necessary.
A: 

I have never tried it, but what about extending or creating new validation attributes that uses a different validation depending on the authorisation role of the user?

RonaldV
By doing this, you would be making the lower layers aware of the security that is going on in the UI or upper layers. But you got me thinking. Perhaps some dependency injection would make sense. I don't think it would be possible to do it on the attribute itself, but perhaps the attribute could just rely on an interface, with the implementation determined by the app that is running?
Adam Roderick
A: 

Those sound like business rules which should be seperate from data access. You should be able to use the same EDM but implement the business rules in the business layer, not the data layer.

DaveB
I agree with the thought. However, the tooling is all built around the idea that property or entity-level validation is accomplished as attributes on the entities or on their metadata "buddy classes." Buddy classes are partial classes, which require them to be in the same assembly as the entity classes. Do you have any info on other ways to accomplish this?
Adam Roderick