Delete Comments Rendered via ajax call

Topics: Customizing Orchard
Oct 17, 2012 at 1:49 PM

I have comments part attached to a blog..when a comment is submitted i display it in the page via a ajax call after storing it in the database..

I also have a delete button attached to each comment..this delete works fine for all the comments except the ones which are just submitted via an ajax call..It worksonly when  the page is refreshed..

Your help is appreciated..

Thanks in advance




Oct 17, 2012 at 4:47 PM

You might need to call contentManager.Flush() to have those changes into the db before executing a select query.

Aug 6, 2013 at 12:45 PM
What would you suggest today, Sebastien, with ContentManager.Flush() having been removed?

I'm having a problem in a situation where I used to use ContentManager.Flush() but now my code broke without that call.

Any advice?
Aug 6, 2013 at 1:20 PM
Flush has been removed as the SessonLocator and Transaction Manager have been rewritten. You no longer need flush and can remove it.
Aug 6, 2013 at 1:32 PM
Edited Aug 6, 2013 at 5:38 PM
Thanks, Nick, for clarifying. Unfortunately, in my code block the expected UPDATE statement never reaches the DB. I'm calling this (EDIT: this is a call across AppDomains, called from a test assembly, executed in the Application Under Test's AppDomain):
    ls => {
        var contentManager = ls.Resolve<IContentManager>();
        var defaultEntry = contentManager.Get(entryId);
        var defaultEntryPart = defaultEntry.Parts
                                .Single(p => p.PartDefinition.Name == "EntryPart");
        var portalConfiguration = ls.Resolve<IPortalConfigurationReaderWriter>()

        foreach (var propertyNameAndValue in propertyNamesAndValues) {
            var propertyInfo = defaultEntryPart.GetType()
            var propertyType = portalConfiguration.DetailPageConfiguration

            if (string.IsNullOrEmpty(propertyNameAndValue.Value)) {
                propertyInfo.SetValue(defaultEntryPart, null, null);
        // used to call contentManager.Flush() here
In NHProf I can see the session and the SessionLocator.Dispose() method being called but like I said, no changes are sent to the DB. Could this be a problem of using Reflection for setting property values? But how else could I do that knowing neither the property's name nor the value's type beforehand?

UPDATE: Does not seem to be related to Reflection. Setting a part's property directly also doesn't persist. Tried this:
        ((dynamic) defaultEntryPart).Town = "BERLIN";
Aug 6, 2013 at 6:43 PM
Having to call flush is usually a smell. That simple properties don't persist is another. Did you check for exceptions after this that would rollback the transaction?