Skip to content

Best practice to update/create a Content Item using the Content Manager I receive in DI when I have multiple nested BagPart #16044

Answered by MarGraz
MarGraz asked this question in Q&A
Discussion options

You must be logged in to vote

@Piedone in the end, I was able to make it work 🥳 but I think we need more deep and accurate documentation on this, because it's something about the behavior Orchard Core framework expects.

The problem was how I was doing the Alter on the BagPart, and how I was doing the add of the BagPart to my content item. In fact, there's a strict way to do it, as fortunately @deanmarcussen explained some years ago here, and it is like:

  1. First, Alter the BagPart content item (always get/create the BagPart through the ContentManager in DI);
  2. Add the BagPart to your main contentItem;
  3. Persist the changes in the DB (CreateAsync or UpdateAsync, etc.);

Note: never do all these operations all together in a …

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@Piedone
Comment options

@MarGraz
Comment options

@Piedone
Comment options

@MarGraz
Comment options

Answer selected by MarGraz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants