views:

15

answers:

1

After some NullReferenceException headache from deep down System.Data.Services I found out that data services doesn't like properties in the EF model marked as protected.

The exception occurs when the data service is initializing and tries to generate metadata for the EF model. Apparently Microsoft decided to throw a NullReferenceException when reflecting protected properties here rather than a meaningful message.

I use a few protected properties to wrap custom types not available in the database. This is a convenient way of representing for example enums in the database. The enum can be represented as a protected string property with a public enum wrapper that converts to and from the string value. This works very well in all other EF usage scenarios and I would rather not abandon the protected properties pattern.

I use self tracking entities that flows around nicely with WCF. Protected properties works well since I have checked "Reuse types in referenced assemblies", which makes my wrapper properties available in all assemblies. I was hoping that I could do something similar with a data service. I realize that I might run into trouble if I want to construct a query where the protected properties is part of the expression, but that is a different problem that could be addressed otherwise.

Is there a (practical) way to use protected entity properties with a data service?

If not, how should I best represent non-db types if I don't want to keep my set of public properties nice and clean?

Obviously I could just make everything public, but that would be a practice that rhymes with globals.

A: 

What about calling SetEntitySetAccessRule?

Craig Stuntz
I'm sorry, I don't see how I should use SetEntitySetAccessRule. As I understand it, the access rule is used to protect a dataset, such that it can be presented to a user as read only for example. This makes good sense when protecting a database exposed by a data service, but it is not really related to my problem, which is essentially an entity / CLR type mapping problem.
Holstebroe
I may have misunderstood your question, but I though you were trying to stop WCF *clients* from seeing your entities. `None` will do that.
Craig Stuntz
No access rights is not the concern for this problem. I am trying to model my STE entities such that there properties are not restricted by the types supported by the database. I support special types with property wrappers, but to clean up my entity classes I wanted to protect the underlying database type (lets say a string wrapped as an enum) to deny the user from modifying them directly. If the underlying properties are exposed, the user can assign bogus values, for example non existing enum values and it would be good OOAD to prevent that.
Holstebroe