0

i want to modify the ContentPageBase, in a functional site, i tried to add a property called for example (weight), but if there is an existing page in the database, the site will malfunction, and throws an Exception, of (Object reference not set to an instance of an object).

how can i correct the already entered data ?

public abstract class ContentPageBase : PageBase, ICommentable
{
   [EditableTextBox("Weight", 10, ContainerName = Tabs.Details)]
        //newly added property.
        public virtual int Weight
        {
            get { return (int)GetDetail("Weight"); }
            set { SetDetail("Weight", value); }
        }
}
Nour
  • 5,252
  • 3
  • 41
  • 66

2 Answers2

1

Yes you get a null refernce when accessing the property and no data exists in DB.

The getter in the old N2CMS must be

 get { return (int)(GetDetail("Weight") ?? 0); }

If you want 0 as default of course.

Best regard

ztaff
  • 243
  • 1
  • 8
0

i figured out how to solve this, just drop the Getters and Setters of the property and use it like this:

public virtual int Weight { get; set;}

this is new feature in N2Cms 2.0.

and when you give a new value to the newly-added property, N2cms add a new record the N2Detail table for the page.

Nour
  • 5,252
  • 3
  • 41
  • 66