What follows is my attempt to define an Entry Model class as described in the blog post https://deliverystack.wordpress.com/2020/07/20/net-core-headless-cms-entry-models-and-entry-model-classes/ to support the Content Type that I described in the blog post at https://deliverystack.wordpress.com/2020/07/21/entry-data-formats-in-headless-cms/ for the Kentico Kontent SaaS headless CMS.
Without the challenges of transforming JSON to HTML as required for Contentful or repeating Field values and Modular Blocks as in Contentstack, my Entry Model for Kentico Kontent feels very simple.
Surprisingly, I get a NullReferenceException accessing the Asset and do not really feel like taking the time to investigate.
Potentially excluding access to Assets and Entries (Items) referenced by Entries (Items) of this Content Type, this Entry (Item) Model class could work with CMS from other vendors.
5 thoughts on “Kentico Kontent .NET Sample Entry Model”
the Asset element is, in fact, a collection of assets. Therefore, you need to use an IEnumerable in the model (and FirstOrDefault() when you try to render it). I tested the adjusted code and it works fine.
For developers’ convenience, we offer a tool that generates the models based on the content types in Kontent automatically – feel free to give it a try https://github.com/Kentico/kontent-generators-net.
I also noticed that you’re using a beta NuGet package. In that case, you might also need to change Asset to IAsset but otherwise, it should work well too.
Please let us know in the GitHub issues (https://github.com/Kentico/kontent-delivery-sdk-net) if you notice any problems. We’ll be releasing a new major version in a couple of weeks.
WordPress press seems to be stripping the angle brackets – so it should be an IEnumerable of Assets 🙂
Thanks Petr! Sorry, I really don’t have time to dig very deep on these. If you want to have someone create an test an updated pastebin, I will change from my link to yours and update the text.
I haven’t tried your model generator. Does it do much beyond create classes with flat lists of simple properties? Does it do something to expose all of the referenced item? Can it pull that data from cached JSON representations of the referenced items, or does it have to pull each item individually, or does it inline/build out the Item reference structure (to some level of depth) before serialization through the RESTful API?
If you could provide a links about any one or more of any of these topics with your headless system, I would be glad to link to them. I’m really here to promote .NET Core and let the customers choose the vendor, which seems to have almost nothing to do with .NET anyway.
And yes, the wordpress WYSIWYG is destroying my productivity and satisfaction as well, while not storing or exposing my content properly. But it’s fast.
I don’t know how I missed it before, but I added the Kontent model generator to the list at https://deliverystack.net/2020/07/20/how-does-net-core-work-with-headless-cms/