R – How to use Read-Only properties defined in partial (Entity Framework) classes over ADO.Net Data Services

entity-frameworknetpartial-classeswcf-data-services

I have objects that are defined by the Entity Framework that I have then added additional methods and properties to via partial classes. I think I understand most of the limitations around doing this, but wanted to confirm something I am seeing (or hopefully learn what I need to do to make this work).

I have a partial class that then has a read-only property that uses a couple of the items to create a calculated field that is read-only. It was curious to see that read-only property did not come back via the ADO.Net Data Services as I was hoping/expecting. i.e. I was expecting to see the properties on the entity framework and the property being definied in code via the partial class come via the Data Service call.

Is this the case? Are the partial classes completely ignored when ADO.Net Data Services is querying for data? If so what is the best practice for getting a read-only type property onto an entity (as I would like to avoid having the same partial classes with different namespaces being cut and pasted into both the client side and server side code bases).

Best Answer

From a Microsoft Forums Post: (see full post here)

"I think you are asking "How to add a read-only property to an existing entity that is exposed by the EF provider"? In V1, there is no good way to do this. For EF, we load the metadata using the EF metadata api's and hence we don't do any reflection. Hence additional properties that you might have added via a partial class will get ignored.

Astoria doesn't yet have a concept of read-only properties. So if we expose any other properties that is not part of the model, we don't know how to deal with them in updates. We don't want to lose data siliently in the server also."

So it looks like this is functionality that is not able to be exposed via ADO.Net Data Services.