This is a migrated thread and some comments may be shown as answers.

Hiding column property in a WCF Data Service

1 Answer 83 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Miguel
Top achievements
Rank 1
Miguel asked on 08 Nov 2013, 06:04 PM

Hello,

I am using OpenAccess to map a multi-tenant database and expose it through a Wcf Data Service. Most of the tables have a “TenantId” column which is necessary to include in the domain classes in order to perform filtering, authorization, crud and so on. For security reasons these TenantId column must not be included in the service’s metadata as it is going to be managed using interceptors.

I have tried to hide it using the IgnoreProperties attribute (microsoft.data.services) but it doesn’t work and I assume the reason has to do with the IOpenAccessMetadataProvider not processing this foreign attribute.

Is there a way to prevent this column to appear in the data service without having to split the domain classes into public and private pairs?

Thanks in advance
M. Mejia

1 Answer, 1 is accepted

Sort by
0
Kaloyan Nikolov
Telerik team
answered on 13 Nov 2013, 04:23 PM
Hi Miguel,

Probably the most easy way to achieve this is to make the tenant property internal. In this case it will not be included in the oData service metadata:

 
The drawback is that you will not be able to access this code outside of your project unless you define the internal visibility attributes for the target projects where you need to access this property. If you need to do this for a number of properties you could use the Model Operations Dialog to do this in a batch.

if you are skipping properties in the metadata then you should find a way how to set them back on the server side when you create/update entities because they will not be serialized to the client and sent back to the server. You could do this with a change interceptor like this:

[ChangeInterceptor("DomainClass1")]
public void onChangeDomainClass1(DomainClass1 entity, UpdateOperations operations)
{
    //entity.TenantId = ???
}
this method should be placed in a partial class of your service.

Please see the attached sample application.

I hope this helps.

Regards,
Kaloyan Nikolov
Telerik
OpenAccess ORM Q3 2013 simplifies your model operations even further providing you with greater flexibility. Check out the list of new features shipped with our latest release!
Tags
Development (API, general questions)
Asked by
Miguel
Top achievements
Rank 1
Answers by
Kaloyan Nikolov
Telerik team
Share this question
or