locked
How to define additional properties in an entity - EF 4 and WCF DataServices 4 RRS feed

  • Question

  • I have an entity which is created from a table in the database. That table has two fields "ID" and "Name". I want to add a 3rd property to the entity which is a combination of both fields called IDName (ID.ToString() + "-" + Name).

    I tried adding another property to the entity specifically, but the compiler complained because the property was not mapped to anything. Then I tried creating a POCO for this entity. I did that as follows:

    public class Site

    {

      public int ID {get; set; }

     public string Name {get; set; }

     public string IDName { get { return ID.ToString() + "-" + Name } }

    }

     

    Now, in following the MSDN examples for using POCO with EF and WCF DataServices, I was able to get this to compile and run just fine. However, the "IDName" property does not show up anywhere in my client proxy, or even by checking the Site object via the URL (http://localhost/service.aspx/Sites).

     

    Monday, April 26, 2010 10:25 PM

Answers

  • Hello,

     

    Welcome to ADO.NET Entity Framework and LINQ to Entities forum!

     

    When WCF Data Service uses the Open Data Protocol (OData) to expose data as a feed.   The data model used with the Entity Framework provider is represented as XML in the certain .edmx file.   The exported data properties of the entities are actually determined by what is defined in the .edmx CSDL.   However, the additional property is only defined inside the POCO class instead of in the CSDL.    Also, as you said, if we add a custom property in the .edmx without mapping it to the database column in the SSDL, EF does not allow it either.   

     

    As a workaround, you can consider use the Feed Customization in WCF Data Services, http://msdn.microsoft.com/en-us/library/ee373839.aspx.   Besides, if the custom property is some combination of the existing properties, we may also use some service operations or handle it at the client side.   For more help, you can see the WCF Data Services forum here, http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/threads.

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, April 27, 2010 7:06 AM

All replies

  • Hello,

     

    Welcome to ADO.NET Entity Framework and LINQ to Entities forum!

     

    When WCF Data Service uses the Open Data Protocol (OData) to expose data as a feed.   The data model used with the Entity Framework provider is represented as XML in the certain .edmx file.   The exported data properties of the entities are actually determined by what is defined in the .edmx CSDL.   However, the additional property is only defined inside the POCO class instead of in the CSDL.    Also, as you said, if we add a custom property in the .edmx without mapping it to the database column in the SSDL, EF does not allow it either.   

     

    As a workaround, you can consider use the Feed Customization in WCF Data Services, http://msdn.microsoft.com/en-us/library/ee373839.aspx.   Besides, if the custom property is some combination of the existing properties, we may also use some service operations or handle it at the client side.   For more help, you can see the WCF Data Services forum here, http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/threads.

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, April 27, 2010 7:06 AM
  • Hi,

     

    I am writing to check the status of the issue on your side.  Would you mind letting me know the result of the suggestions? 

     

    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, May 5, 2010 1:56 AM