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

I have objects that are defined by the Entity Framework and then I have added additional methods and properties via partial classes. I think I understand most of the limitations associated with this, but wanted to confirm what I see (or hopefully find out 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 elements to create a read-only computed field. It was curious to see that the read-only property was not returning via ADO.Net data services as I hoped / expected. that is, I expected to see properties in the entity framework, and a property defined in code via a partial class came through a call to the data service.

This is true? Are partial classes partially ignored when ADO.Net Data Services requests data? If so, what is the best practice for getting a read-only property for an object (as I would like to avoid using the same partial classes with different namespaces that were cut and pasted on both client and server side) ...

+1


source to share


3 answers


From the Microsoft Forums post : ( see the full post here )

"I think you are asking," How do I add a read-only property to an existing object that is exposed to the EF provider? "There is no good way to do this in V1. For EF, we load metadata using the EF api's metadata and therefore we do not no thought, therefore additional properties that you can add via the partial class will be ignored.

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



So it looks like this is a functionality that cannot be discovered through ADO.Net data services.

+3


source


There are two separate issues here: the base model (EF) and the WCF / mex layer. Your additional properties won't be part of the edmx model, but I'm wondering if the issue is related to the WCF / mex aspect.

However, even if it worked, ADO.NET Data Services was passing data, not logic. Therefore, relying on computed properties is not a safe option: the client will not have formulas - only raw values.



To see what it is, try making the read / write property (even if writing doesn't do anything useful) and make sure the [DataMember] attribute is set, and so on.

+2


source


I think the problem is with XML serialization, it only serializes properties using get and set methods. Otherwise, it could not be serialized. Add an empty set method to your property and watch as you go.

Rob

-1


source







All Articles