This project is read-only.

Old topic but new thought

Topics: Core
Aug 25, 2014 at 8:12 AM
orchard uses ContentPart and ContentPartRecord to distinguish type and db instance(or mapping).

so, could anyone tell me, why do we use these two different class? Is there any advantage? why not just use ContentPart ?

I'm tired of writing nearly the same code in both class.
Aug 25, 2014 at 8:51 AM
The ContentPartRecord is a representation of a table row in the database. The ContentPart does not always represent a row in the database. Usually it represents the record too, but it has advantages to split those two:
  • The ContentPart can have variables that come from another part for example, or that are based on another variable that does not need to be stored in the database.
  • You are able to manipulate the data before storing/after retrieving the content from the database.
Aug 25, 2014 at 3:55 PM
Like @sanderg wrote, there are advantages from splitting those two.

But in most cases, you don't have to use the backing record at all. Since Orchard 1.8, you can just use a ContentPart and use its Store/Retrieve methods to store data in the underlying XML document storage. Backing record is necessary only if you want to query on certain properties.
Aug 26, 2014 at 12:58 AM
Edited Aug 26, 2014 at 12:58 AM
thanks to @sanderg and @pszmyd,

since orchard references nhibernate and castle, why not just using Active Record?