2
votes

I have a custom Board entity with a 1:N relationship to a custom Board Seat entity. I have a post-update plugin on the Board entity that tries to loop through all the Board Seats related to the Board being updated. I've tried both a pre and post image and the relationship is null on both even though the Board has several Board Seats associated with it.

var board = EntityImage.ToEntity<my_boards>();
foreach (var seat in board.board_to_boardseat_relationship)
{
    // Process each seat
}

I'm using strongly typed entities and the type of board.board_to_boardseat_relationship is System.Collections.Generic.IEnumerable<my_boardseat>. It appears that the relationship simply isn't getting populated in either the pre or post image. When I register the image I select all attributes. Any idea how to populate this relationship?

1

1 Answers

2
votes

Mike,

It doesn't get populated because all the attributes are only the attributes of the Entity. You'd have to use some kind of retrieve function to get all the seats associated with this particular board. They are never included in your Post- or Pre-Image (or Target) Below is some sample code:

Entity PostImage = (Entity)m_localcontext.PluginExecutionContext.PostEntityImages["PostImage"]; my_board board = PostImage.ToEntity();

 var seatsList = orgContext.CreateQuery<my_boardseat>().Where(c => c.boardId.Id == board.boardId).ToList();

 if (seatsList.Count > 0)
 {
      foreach (my_boardseat seat in seatsList)
      {
        //Your Code Here
      }
 }