May 30, 2014

Orchard Default Value in InfoSet

Orchard 1.8 recently opened up InfoSet storage, which was previously used by fields and content type settings, to parts as well, meaning you don't need to worry about any pesky migrations. So I have been playing around with this and have converted many of my site setting parts to use the InfoSet storage. Much of the time I want to assign a default value to my site settings. This was simple using migrations with the old record storage system.

.Column<string>("ExcludedColumns", column => column.NotNull().WithDefault("UserPart.HashAlgorithm"))

However, it wasn't immediately obvious to me if this was possible with the new InfoSet storage and since Orchard 1.8 was released relatively recently, there is not a lot of documentation. But, of course, the gurus who make Orchard had catered for all us lovers of default properties and there is an optional property on the retrieve method called "defaultValue". The default value will appear in your site setting views for editing, so it isn't just a silent default.

public string ExcludedColumns
{
 get { 
  return this.Retrieve(x => x.ExcludedColumns, "UserPart.EmailStatus"); 
 }
 set
 {
  this.Store(x => x.ExcludedColumns, value);
 }
}

So there we have it, simples.

Tags: Orchard

1 Comment

Add a Comment