Customizing the loading of related Entities when using LoadProperty() and POCOs RRS feed

  • Question

  • Hi,


    I need to execute some business logic when loading related objects from the database and I don’t know how to do this “right”.


    I have the following scenario:  A Computer can be assigned to one or more Groups from which it inherits variables.

    E.g.: I have two Groups: Berlin and Sydney and each of them has a variable “TimeZone” set to UTC+1 respectively UTC+10. When my Computer PC1 is in the Sydney group it inherits the value of the “TimeZone” from the parent Group.


    As variables can be set on the computer itself, on the parent group or even on the parents parent group (and so on), there is a logic that computes the resulting list of values for a given computer.

    On my Computer Entity I created two navigation properties one for the variables that are set directly on the Computer “DirectVariableValues” and one that should return all variables including those inherited “ActiveVariableValues”.


    From the Client side I want to be able to load the “ActiveVariableValues” as follows:


                    Computer pc1 = ctx.Computers.Where(c => c.Name == "Comp1").Single();

                    ctx.LoadProperty(pc1, "ActiveVariableValues");


    Is there a way to hook to this LoadProperty call and to call e.g. a SPROC that retrieves the computed VariableValues form DB or another way to implement this functionality?

    I would appreciate any hint or suggestion.


    (I am using POCOs and want to find an alternative to a Function Import.)


    Monday, October 31, 2011 3:07 PM

All replies

  • Hi,

    I think you can refer this link: http://msdn.microsoft.com/en-us/library/dd456855.aspx

    Have a nice day.

    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, November 2, 2011 9:07 AM
  • Thanks for your answer Alan.

    My scenario is a bit more complex. When I load the “ActiveVarialbeValues” Property I want to execute some logic that could look like this (very simplified):

    1)      Get all Variables Values that are directly set on the Computer  (using a join table Computer<->VariableValue)

    2)      Get all Variables Values that are set on the Computer Parent Groups and those Parents (using 2 join tables: Computer<->Groups and Groups<->Varialbevalues)

    3)      Merge this Values considering defined rules

    4)      Return the resulting list VariableValue objects

    I suppose it would be better to execute this kind of logic on the database side, but I am open to any suggestion.

    I hope this helps understanding what I am trying to do.

    Wednesday, November 2, 2011 10:44 AM