Virtual Happy Hour canceled for Friday May 31st.

Try our conversational search powered by Generative AI!

Ruslan Minasian
Nov 4, 2010
  3632
(0 votes)

Custom Property Type and SaveData Method

In out project we use PropertyPageReferenceCollection to store references to local pages. It has PageReferenceCollection under the hood and calls its Parse and ToString methods to load and save the data. Evetything was fine until we decided to make some property (let’s call it Links) of this type required. The application started to crash while loading the page with empty Links property.

I’ve spend a lot of time looking how to prevent LoadData from crash while the error was in SaveData method. When LocalPageProvider loads a page it goes through all the properties from DB calls PropertyData.LoadData method for each property which value is not DBNull.Value. Since our SaveData implementation used PageReferenceCollection.ToString it returned string.Empty for empty collection and that value was stored in the DB. Then, after we set Links property as required, LoadData started to crash since string.Empty caused PropertyData.Clear to be called for required property.

Moral: always implement SaveData property so it returns null if PropertyData.IsNull is true.

Nov 04, 2010

Comments

Please login to comment.
Latest blogs
Blazor in Optimizely CMS 12 with .NET 8

How to enable support for Blazor components in Optimizely CMS 12 after upgrading to .NET 8.

Ted | May 30, 2024 | Syndicated blog

Build a headless blog with Astro and Optimizely SaaS CMS

I’m a big fan of using the right tool for the right job. I’m also a big fan of Astro , for the right use case. Let's explore Astro to see what it's...

Jacob Pretorius | May 28, 2024

Microsoft announces Natural language to SQL

Finally, Microsoft launches "Natural language to SQL," after it has been available for several months in Optimizely CMS!

Tomas Hensrud Gulla | May 23, 2024 | Syndicated blog

Five easy ways to start personalizing your content right now

If you clicked on this article, you already know that getting the right message to the right person at the right time helps drive conversions and...

Kara Andersen | May 23, 2024