Cascade saving children objects in Orchard CMS

matonghoalam's Avatar


17 Sep, 2015 03:29 AM

Lets say I have an object called Company that is represented like so:

public class Company
{ public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual Address Address { get; set; } }

public class Address
{ public virtual int Id { get; set; } public virtual string Line1 { get; set; } public virtual string Line2 { get; set; } public virtual string Line3 { get; set; } public virtual string Town { get; set; } public virtual string County { get; set; } public virtual string Postcode { get; set; } public virtual double Longitude { get; set; } public virtual double Latitude { get; set; } } When I create a new company, I also want the new address to be created too. At the moment, I can only get this to work by creating the address record and then creating the company record separately:

public ActionResult Add(Company company)
    return RedirectToAction("Index");

(Where _addressRepo and _companyRepo are of type IRepository

and IRepository respectively)

How can I get all child objects to cascade save? So that ideally, when I call _companyRepo.Create(company);, Orchard handles all the child records for me?

I tried creating a new attribute so that properties can be marked as Cascade Save Update, but If I put a breakpoint on the Apply method it never appears to get hit.

public class CascadeSaveUpdateAttribute : Attribute {

public class CascadeSaveUpdateConvention :

protected override void Apply(CascadeSaveUpdateAttribute attribute, ICollectionInstance instance)

} What can I do to get this Cascade Save functionality working?

cách làm sữa chua at fanrang

This discussion was closed! See this FAQ for more information:

  1. Why am I seeing <system-region> tags around my published content?

    The <system-region></system-region> tags are automatically added to rendered and published content that does not contain valid XML. Specifically, due to the lack of a root element when Cascade Server attempts to validate the content as XML during the rendering and publishing process.

    In order to generate non-XML, surround the region(s) with a "dummy" tag that is wrapped in a #cascade-skip code sec...

    See more..
  1. matonghoalam closed this discussion on 17 Sep, 2015 03:29 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac