Posted on 21/02/2018 13:42:41
Hi Adrian,
1) You can get intellisense in Visual Studio when using code first items.
So instead of doing this with a regular item...
string myText = item.GetString("MyText");
... you can do this with a code first item...
string myText = item.MyText;
With intellisense you can easily see all the available fields (properties) on an item. With regular items you will have to remember the system names of the item fields - or use TemplateTags to see what is available.
If you need to implement a lot of advanced logic for handling your items then code first can make it a lot easier. You can avoid problems caused by missing fields or misspelling of field names because you get full intellisense and compile time errors. With regular items you can only work with key/value pairs and errors caused by missing or misspelled field names would only show up at runtime.
2) Code first items can only be changed by a developer. Regular items can be changed by any user that has access to Settings > Item Types.
- It can be an advantage to use code first items if you want to ensure that item type definition is "locked", but it can also make it more cumbersome to make changes in the future.
3) In general it doesn't have any considerable effect on performance whether you use regular items or code first items. However, it really depends on your code.
4) With code first items you can override the save and delete logic, but you can achieve the same with any type of item by implementing notification subscribers for ItemNotification.Saving, ItemNotification.Saved, ItemNotification.Deleting, ItemNotification.Deleted.
Other than that I think it is mostly about what the developers prefer.
You can start out with model first items and then replace them with code first items later on if needed.
Best regards,
Morten