[11.8.5] Storing a list of strings/StringDictionary alternative?

Vote:
 

So, I'm in the process of upgradering a CMS+Commerce solution from 7.5 to 11.8.5.

The site uses a StringDictionary metafield, and this has been discussed at length throughout the years.

My question now is - what is the recommended way of storing a List on a catalog content type?

I had a look at https://world.episerver.com/forum/developer-forum/Episerver-Commerce/Thread-Container/2014/7/MetaDataTypeStringDictionary-from-code/, but that discussion is very old, so I was thinking there must be a better/simpler way today?

That code also crashes the CMS part of the site, with "Type '[...].StringDictionary' could not be mapped to a PropertyDefinitionType"...

#194880
Jul 05, 2018 13:42
Vote:
 

if it's just a List<string>, it has native support by IList<T>, you don't even need StringDictionary for that 

#194882
Jul 05, 2018 14:52
Vote:
 

So the way to go is:

  1. Delete the old StringDictionary metafield (losing all current values - not a big problem).
  2. Create an IList<string> property in the model class(es).
  3. Run the import to make sure the products and variations are configured properly again.

Cool.

Thanks (again)! :)

#194884
Jul 05, 2018 15:05
Vote:
 

It's worth noting that StringDictionary is not just a string list - it is a "dictionary", so you can define pair like <"hello","world">

Of course if you are using StringDictionary as just a string list then it'll work :) 

#194885
Jul 05, 2018 15:10
Vote:
 

I just tried it, and I get an exception about List<string> "can not be mapped to a MetaDataType" :(

#194886
Jul 05, 2018 15:11
Vote:
 

You probably need [BackingType(typeof(PropertyStringList))] attribute :)

#194887
Edited, Jul 05, 2018 15:13
Vote:
 

Doh! :)

Cool, everything works now. I hope. Still haven't gotten to updating the importers, but at least nothing crashes so far :)

Thanks again for you help!!

#194895
Jul 05, 2018 16:00
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.