Generated create object method takes in readonly properties

Aug 27, 2009 at 4:01 AM

When you generate the static method that creates a new instance of the generated object with all the properties set, are you able to filter out from the constructor all the properties that are readonly? Your behaviour does match what the generated classes do in a .NET client but is a bit useless exposing a method that throws errors when used.

Aug 27, 2009 at 7:53 AM
Edited Aug 27, 2009 at 3:53 PM

We generate classes from the ADO .NET Data Service metadata (/$metadata appended at the end of service URL). This metadata does not specify wheather property is readonly. But you do get proper error message when you try to modify readonly property.

The generated create object method takes in all "NOT NULLABLE" properties. These are not readonly properties. 




Aug 27, 2009 at 9:59 PM
Edited Aug 27, 2009 at 10:15 PM

Thanks for the tip about the metadata url appendage, this is the metadata that comes through for me:

<Property Name="ID" Type="Edm.Int32" Nullable="false" p7:SetterAccess="Internal"/>

Basically in my case I'm using an integer identity as the primary key for my table so it's not nullable and but neither can it be set. To indicate it as such in the ADO.NET Data Entity Model I'm changing the setter of the property to something other than public. Just so you're aware I tried hiding some other properties by changing the getter to internal but it causes a runtime exception and found that ADO.NET Data Service does not yet support non-public getters, changing the getter back to public does cause the p7:GetterAccess="Public" attribute to be emitted.

Sep 8, 2009 at 5:08 AM

hi mcm_ham,

 I see that you have made the primary key Internal (p7:SetterAccess="Internal") .
 The ADO.NET Data Services runtime does not support non-public properties on entity types.
 You can read a discussion we had about the same issue on the MSDN forums for ADO.NET Data Services.
 Exposing ReadOnly Partial Classes of Entities via ADO.Net Data Services
To make this scenario work , you will need to make the property's setter public.

Sep 8, 2009 at 11:38 PM

|  Astoria doesn't yet have a concept of read-only properties.

Strange, because this is working perfectly fine for me on dotnet and php clients. On the dotnet client the property only has a getter causing a compilation error if you try to set it. That said the main discussion in the thread was the ability to add your own propeties if you are exposing the Entity Data Model through the Data Service and indeed the custom properties do not come through.