Search code examples
silverlightwcf-ria-services

partial method OnCreated not called when expected


I've extended my domain class on the silverlight client side in a partial class. Specifically, I've added a RelayCommand property that I will be binding a button to. The RelayCommand property needs to be initialized, and so it would seem that the best place to do that would be in the OnCreated partial method.

However I gather that when the object from the server is materialized on the client side its constructor is not called (which seems totally wrong headed to me!) Since it's constructor is not called, it's not calling the OnCreated Method.

Is there a config or a convention for getting this OnCreated partial method to be called as the objects are materialized?


Solution

  • The partial method OnCreated() is only called when you instantiate an Entity using its default constructor.

    If you want to initialize your loaded entities you have to override the OnLoaded method. A boolean is passed to it that specifies if the entity was loaded first time or not.