Search code examples
entity-framework-4propertieswcf-data-services

Best way to ignore properties with WCF Data Service


I'm using ASP.NET MVC4 (EF Code-first) with WCF ADO.NET Data Service October 2011 CTP. I have an issue - I don't know how to ignore sensitive properties (like email).

I tried using an ADO.NET Entity Data Model (.edmx) and find the declaration of the sensitive property:

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public global::System.String MySensitiveProperty
{
    get
    {
        return _MySensitiveProperty;
    }

and changing the getter:

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public global::System.String MySensitiveProperty
{
    get
    {
        return "No data here!";
    }

Is there any better and simpler solution for my issue?


Solution

  • In such case why do you expose that property? Once you do it this way you say that your application (no part of your application) never needs email property. In such case delete the property from entity mapped in EDMX and it will be never accessible.