Using EntityPropertyMappingAttribute to change the name of a property RRS feed

  • Question

  • Hello, I am using WCF Data services to connect to an Atom feed that I cannot change the schema of. When I run the client code generator, it generates some data objects that look like the following:


    public partial class Company_Name_core_form : global::System.ComponentModel.INotifyPropertyChanged
      [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Services.Design", "1.0.0")]
      public string Company_Name_Entity_Name

    I am attempting to change the properties so that they don't use the gigantic names like "Company_Name_Entity_Name" (don't worry I won't be regenerating the service reference code).


    From what I can gather, it looks like this is possible to do using the EntityPropertyMappingAttribute, but I cannot seem to get it to work. I attach it to the entity:


    [EntityPropertyMappingAttribute("EntityName", "Company_Name_Entity_Name", null, "http://schemas.microsoft.com/ado/2007/08/dataservices", true)]

    So what I'm trying to do here is make it so that with the code object I can simply say "item.EntityName", rather than "item.Company_Name_Entity_Name", and have it still map to the proper attribute exposed by the server.


    I don't know what I'm doing wrong here, and I can't find any examples anywhere that describe how I'm supposed to use this for this scenario. Most boggling is that I literally have no idea what to use for targetNamespacePrefix and targetNamespace. If I leave out targetNamespace, then I get exceptions saying that it's empty (even though the docs say it's ok... I reflectored the code, it's not ok, it will always throw an exception if it's empty).


    Anyway, I would greatly appreciate it if anyone is able to help me with this. It's driving me crazy. Thanks!

    Friday, January 21, 2011 10:10 PM


  • The EntityPropertyMappingAttribute is used to support feed customization. You can read more about it in the Feed Customization topic. The intent of this feature is to enable you to map property data from entity in the data service to specific elements defined by Atom Syndication (such as Author/Email and Title) and to custom elements. The codegen tool sees these mapping in the data service metadata and applies the EntityPropertyMappingAttribute to generated types to make the client aware of these customizations. In this way, both the client and service can reason about the same entities while using a customized feed in the exchanges.

    Unfortunately, this attribute does not enable you to simply rename the properties of your entities.

    Glenn Gailey

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Saturday, January 22, 2011 9:40 AM