views:

1321

answers:

3

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).

+2  A: 

There are two separate concerns here - the base model (EF), and the WCF/mex layer. Your additional properties will not be part of the edmx model, but I wonder if the issue isn't more related to the WCF/mex aspect.

However, even if it worked, ADO.NET Data Services transfers data, not logic. So relying on calculated properties isn't a safe option : the client won't have the formulae - just the original values.

To find out which it is, try making the property read/write (even if the write doesn't do anything useful), and ensure the value has a [DataMember] attribute, etc.

Marc Gravell
I do know that it would only transfer data, which is what I was hoping (no need for logic on the client). It does look like there might not be a way to do this in ADO.Net Data Services yet. Thanks for your help though.
ChrisHDog
A: 

I think the problem is that with XML serialization, it only serializes properties with get and set methods. Otherwise it couldn't de-serialize. Add an empty set method to your property and see how you go.

Rob

Robert Wagner
+3  A: 

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.

ChrisHDog