none
ExecuteStoreQuery returning EntityObject ignores custom properties RRS feed

  • Question

  • I have added a property ("CustomProperty") to an EntityObject via a partial class definition.  I want the property to be populated via a matching column from ExecuteStoreQuery.  For example:

    ExecuteStoreQuery<MyTable>("Select *, CustomProperty from MyTable") 

    CustomProperty is ignored if MyTable is an EntityObject.  If MyTable is a POCO, it works.

    According to the MSDN documentation it should work:

    (http://msdn.microsoft.com/en-us/library/ee358758.aspx)

    "Each property of the type:

    • Must have a setter.
    • Must correspond to a primitive type in CSDL.
    • Must correspond to a column name in the resulting DbDataReader (the provider implementation determines whether a column has the same name as the property). If the name of the type's property does not match a field of the DbDataReader, the Entity Framework materializes the default value of the property if it is defined in the conceptutal model."

    It seems that if TElement is an EntityObject the behaviour is different.  Any ideas?

     

    Wednesday, January 25, 2012 12:01 AM

Answers

  • Hi,

    For POCO objects, do you mean you are using Code First?  If so, all the EF metadata is generated during runtime, and the custom properties will also be generated in the metadata.   However, for using EntityObject, the metadata is loaded into memory from SSDL, CSDL and MSL.   If we define custom properties in EntityObject, EF won't add this property into the CSDL metadata.   I think that's why ExecuteStoreQuery ingores custom properties in EntityObject. 

    Good day!

    Thanks


    Michael Sun [MSFT]
    MSDN Community Support | Feedback to us
    Wednesday, January 25, 2012 5:27 AM
    Moderator