+1-888-365-2779
Try Now
More in this section

Forums / Bugs & Issues / Application_Start code throwing Nolics exception

Application_Start code throwing Nolics exception

2 posts, 0 answered
  1. ColinBowern
    ColinBowern avatar
    20 posts
    Registered:
    12 Aug 2012
    21 Feb 2009
    Link to this post
    I am trying to do some work in the Application_Start method on the forums:

        void Application_Start(object sender, EventArgs e) 
        [ 
            ForumManager forumManager = new ForumManager(); 
            DateTime ExpiryDate = DateTime.Today.AddDays(-45); 
     
            IList forums = forumManager.GetForums(false); 
            foreach (IForum forum in forums) 
            [ 
                if (forum.Name == "Career Opportunities"
                [ 
                     
                    IList posts = forumManager.GetForumThreads(forum, true); 
                    foreach (IPost post in posts) 
                    [ 
                        if ((post.DateCreated < ExpiryDate) && 
                            (post.Status == PostStatus.PostVisible)) 
                        [ 
                            post.Status = PostStatus.PostHidden; 
                            forumManager.SavePost(post); 
                        ] 
                        else if ((post.DateCreated < ExpiryDate) && 
                            (post.Status == PostStatus.ThreadVisible)) 
                        [ 
                            post.Status = PostStatus.ThreadHidden; 
                            forumManager.SavePost(post); 
                        ] 
                    ] 
                ] 
            ] 
        ] 

    However Nolics doesn't seem to like it:

    You cannot change a value of an object that is not in transaction.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: Nolics.ORMapper.Base.NolnetException: You cannot change a value of an object that is not in transaction.

    Source Error:

    Line 37:                         (post.Status == PostStatus.ThreadVisible))
    Line 38:                     [
    Line 39:                         post.Status = PostStatus.ThreadHidden;
    Line 40:                         forumManager.SavePost(post);
    Line 41:                     ]

    Source File: c:\Projects\MetroTorontoUG\3.6\Global.asax    Line: 39

    Stack Trace:

    [NolnetException: You cannot change a value of an object that is not in transaction.]
       Nolics.ORMapper.Base.OdbClassHelper.CheckAssign(IOdbView clView, String propertyName, Object oldValue, Object newValue) +182
       Telerik.Forums.Data.Post.set_Status(PostStatus value) +121
       ASP.global_asax.Application_Start(Object sender, EventArgs e) in c:\Projects\MetroTorontoUG\3.6\Global.asax:39
    


    Any thoughts on how to get around it?  I don't think I should have to manage the Nolics engine.

    Cheers,
    Colin
  2. Slavo
    Slavo avatar
    295 posts
    Registered:
    24 Sep 2012
    23 Feb 2009
    Link to this post
    Hi Colin,

    This is a common Nolics error, every object has to belong to a transaction before you do any persistence with it. Internally all this is wrapped by the Sitefinity API and you don't have to worry about it. In your case however, you are directly calling Nolics code, as the IPost object is a Nolics object. Hence the object is not joined into a transaction.
    The way you can circumvent this is by explicitly getting the object through the ForumManager by providing the ID from the Nolics object. It would descrease performance a bit, since you'll have one more database access, but if you are running the code only when the application starts, this shouldn't be a problem. Here's the code:

        Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager(); 
        DateTime ExpiryDate = DateTime.Today.AddDays(-45); 
     
        IList forums = forumManager.GetForums(false); 
        foreach (Telerik.Forums.IForum forum in forums) 
        { 
            if (forum.Name == "Career Opportunities"
            { 
     
                IList posts = forumManager.GetForumThreads(forum, true); 
                foreach (Telerik.Forums.IPost post in posts) 
                { 
                    if ((post.DateCreated < ExpiryDate) && 
                        (post.Status == Telerik.Forums.PostStatus.PostVisible)) 
                    { 
                        Telerik.Forums.IPost newPost = forumManager.GetPost(post.ID); 
                        newPost.Status = Telerik.Forums.PostStatus.PostHidden; 
                        forumManager.SavePost(newPost); 
                    } 
                    else if ((post.DateCreated < ExpiryDate) && 
                        (post.Status == Telerik.Forums.PostStatus.ThreadVisible)) 
                    { 
                        Telerik.Forums.IPost newPost = forumManager.GetPost(post.ID); 
                        newPost.Status = Telerik.Forums.PostStatus.ThreadHidden; 
                        forumManager.SavePost(newPost); 
                    } 
                } 
            } 
        } 


    On the side, I want to mention that we plan to do a lot of rework for the Forums module. We will make it GenericContent based and it would be able to reuse all filtering features of GenericContent. Once that is released, you will not have to hide expired posts in this way, but the Forums controls would be able to filter the output for you.
    Hope this helps.

    Greetings,
    Slavo
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
2 posts, 0 answered