none
Ignore properties attribute not working in WCF Data Services 5.0 RTM Release

    Question

  • Hi,

    As soon as I updated to the 5.0 release I could no longer get IgnoreProperties to work with this simple test...

       [System.Data.Services.IgnoreProperties("State")]

       public class Tmp

       {

           public Guid ID { get; set; }

           public int Test1 { get; set; }

           public TestStateEnum State { get; set; }

       }

    Followed by the typical error you would expect the ignore attribute to resolve.

    The server encountered an error processing the request. The exception message is 'The property 'State' on type 'DomainModel.Tmp' is not a valid property. Make sure that the type of the property is a public type and a supported primitive type or a entity type with a valid key or a complex type.'. See server logs for more details. The exception stack trace is:

    at System.Data.Services.Providers.ReflectionServiceProvider.BuildTypeProperties(ResourceType parentResourceType, IDictionary`2 knownTypes, IDictionary`2 childTypes, Queue`1 unvisitedTypes, IEnumerable`1 entitySets) at System.Data.Services.Providers.ReflectionServiceProvider.PopulateMetadataForTypes(IDictionary`2 knownTypes, IDictionary`2 childTypes, Queue`1 unvisitedTypes, IEnumerable`1 entitySets) at System.Data.Services.Providers.ReflectionServiceProvider.PopulateMetadata(IDictionary`2 knownTypes, IDictionary`2 childTypes, IDictionary`2 entitySets) at ...

    Any idea what happened in this release?

    Thanks!

    Wednesday, April 11, 2012 4:34 PM

Answers

  • Hi,

    Make sure that the assembly in which the class with the attribute is defined references the new Microsoft.Data.Services assemblies and not the old System.Data.Services assemblies. Otherwise the attributes won't be correctly recognized.

    Thanks,


    Vitek Karas [MSFT]

    • Marked as answer by BotHead Wednesday, April 11, 2012 6:19 PM
    Wednesday, April 11, 2012 5:01 PM
    Moderator

All replies

  • Hi,

    I'm working on reproducing this issue locally and will reply back in a few minutes. Thanks for reporting this!


    Matt Meehan (WCF Data Services / OData)

    Wednesday, April 11, 2012 5:00 PM
    Moderator
  • Hi,

    Make sure that the assembly in which the class with the attribute is defined references the new Microsoft.Data.Services assemblies and not the old System.Data.Services assemblies. Otherwise the attributes won't be correctly recognized.

    Thanks,


    Vitek Karas [MSFT]

    • Marked as answer by BotHead Wednesday, April 11, 2012 6:19 PM
    Wednesday, April 11, 2012 5:01 PM
    Moderator
  • That was exactly it, thanks Vitek!  I updated all my references except in the project where my class definition lived.

    Wednesday, April 11, 2012 6:17 PM
  • Hi,

    Make sure that the assembly in which the class with the attribute is defined references the new Microsoft.Data.Services assemblies and not the old System.Data.Services assemblies. Otherwise the attributes won't be correctly recognized.

    Thanks,


    Vitek Karas [MSFT]

    Hi Vitek,

    I've just run into the same issue. I'm trying to work round the problem of enum properties in my code first data model. As a test I create a small class without enums and tried to ignore one or more properties:

    using System;
    using System.Data.Services;
    
    namespace WcfServiceApp
    {
        [IgnoreProperties("Genre")]
        public class Book 
        {
            public int Id { get; set; }
            public string Title { get; set; }
            public string Author { get; set; }
            public int Genre { get; set; }
        }
    }

    I'm referencing EF5.0, Microsoft.Data.Edm 5.0.1, Microsoft.Data.OData 5.0.1, Microsoft.Data.Services 5.0.1 and Microsoft.Data.Services.Client 5.0.1. in my data service class I set:

     config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;

    The property is still visible via an OData query and if I use an enum property I get a crash. Any idea what's going wrong?

    Thanks.

    Tuesday, July 17, 2012 11:00 AM
  • I get the same and this is my properties :

    <IgnoreProperties("Localisation")>
    Partial Public Class t_terr_localisation
        Public Property CODE_GEO As String
        Public Property NOM As String
        Public Property CODE_ENTITE As Nullable(Of Short)
    
        Public Property Localisation As System.Data.Spatial.DbGeography
    
    End Class
    I have no idea why the attribute wont work...


    Micael Levesque


    • Edited by micaël Friday, August 03, 2012 2:25 AM
    Friday, August 03, 2012 2:22 AM
  • The IgnoreProperties attribute is currently only supported for reflection provider. EF providers doesn't recognize that attribute.

    Thanks,


    Vitek Karas [MSFT]

    Friday, August 03, 2012 1:40 PM
    Moderator
  • Hi again,

    I advanced with another way, but i did get blocked on registering the distances functions with the data service. The examples given that i ve found on the web are outdated and the system.spatial dll does not contain the same methods anymore :

    using-geospatial-data

    how do you register now for the distances ?

    // Register my operations
    SpatialOperations.Register(2.0, new MyOperations());

    does not exist in spatialOperations class, not on MSDN, no where in fact...

    So an example would be appreciated how to use the spatial type with WCF data services thanks!


    Micael Levesque

    Monday, August 06, 2012 2:59 PM
  • Sorry for the delay Micael,

    I've made a quick post in the comments for that blog post, but the short answer is:

    SpatialImplementation.CurrentImplementation.Operations = new MyOperations();

    We forgot to update the CTP blog posts to reflect changes made based on feedback, and didn't make new posts for every feature. We hope to get a new updated blog post soon after our next release.


    Matt Meehan (WCF Data Services / OData)

    Wednesday, September 05, 2012 5:28 PM
    Moderator