Hiding column property in a WCF Data Service

Thread is closed for posting
2 posts, 0 answers
  1. Miguel
    Miguel avatar
    1 posts
    Member since:
    Mar 2013

    Posted 08 Nov 2013 Link to this post


    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

  2. Kaloyan Nikolov
    Kaloyan Nikolov avatar
    118 posts

    Posted 13 Nov 2013 Link to this post

    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:

    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.

    Kaloyan Nikolov
    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!
Back to Top