Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Marek K Chmiel 2 posts 22 karma points
    Jun 21, 2021 @ 16:28
    Marek K Chmiel
    0

    Code First Models

    Hi,

    I am new to Umbraco 9 and am trying to find how I can have my own partial class models show up in backoffice?

    My appSetting.json has the following but have tested the other options to see if my document type will show up.

    "ModelsBuilder": { "ModelsMode": "SourceCodeManual", "Enable": true

    As a test I created the below:

    namespace Umbraco.Cms.Web.Common.PublishedModels
    

    { [PublishedModel("sitePage")] public partial class SitePage : PublishedContentModel { private IPublishedValueFallback _publishedValueFallback;

        public new static IPublishedContentType GetModelContentType(IPublishedSnapshotAccessor publishedSnapshotAccessor)
            => PublishedModelUtility.GetModelContentType(publishedSnapshotAccessor, PublishedItemType.Content, "sitePage");
    
        public static IPublishedPropertyType GetModelPropertyType<TValue>(IPublishedSnapshotAccessor publishedSnapshotAccessor, Expression<Func<SitePage, TValue>> selector)
            => PublishedModelUtility.GetModelPropertyType(GetModelContentType(publishedSnapshotAccessor), selector);
    
        public SitePage(IPublishedContent content, IPublishedValueFallback publishedValueFallback) : base(content, publishedValueFallback)
        {
            _publishedValueFallback = publishedValueFallback;
        }
    
        [ImplementPropertyType("test")]
        public virtual string Test => this.Value<string>(_publishedValueFallback, "test");
    }
    

    I did check the dll and the class is available.

    I found this: https://our.umbraco.com/Documentation/Reference/Templating/Modelsbuilder/Builder-Modes and it leads me to believe that if I have the full version of model builder it should work. That being said am I on the right track that this is what I need and is there a model builder full version available for Umbraco 9 beta 3?

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Jun 21, 2021 @ 17:08
    Nik
    0

    Hi Marek,

    Umbraco doesn't currently, and I don't believe does in v9, support Code First models.

    Models Builder generates models from your Umbraco Document Types which you can then extend, however these extensions do not show in the Umbraco back office.

    The Umbraco back office deals with IContent items, where as front end rendering and Models Builder deals with IPublishedContent.

    Thanks

    Nik

  • Marek K Chmiel 2 posts 22 karma points
    Jun 21, 2021 @ 17:15
    Marek K Chmiel
    0

    Ah k makes sense, thank you man.

Please Sign in or register to post replies

Write your reply to:

Draft