Copied to clipboard

Flag this post as spam?

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


  • Daniel Rogers 134 posts 712 karma points
    Dec 06, 2022 @ 06:33
    Daniel Rogers
    0

    partial classes across packages

    Using Umbraco 10.3.2

    I'm not at creating a package yet but that is where this has to end up.

    I have a content page "samplePage" that is compiled using modules builder to ModelsGeneratedAssembly.

    I have then I want to add to "samplePage" some other variables stored in a custom database so I declar this

    namespace Umbraco.Cms.Web.Common.PublishedModels
    {
        public partial class IsamplePage: PublishedContentModel 
        {
            ...............
        }
    }
    

    Which then compiles this into my project dll.

    This I have done in version 8 but of course everything was compiled into the one project dll as I was doing the models builder slightly different.

    How do I do this so as it doesn't matter what way the end user decides to setup there models builder.

    Or am I best to just setup the database info as there own public class.

  • Nik 1601 posts 7202 karma points MVP 6x c-trib
    Dec 07, 2022 @ 09:50
    Nik
    0

    Hi Daniel,

    You cannot spread partial classes across different DLL's. It is a .Net limitation on the concept. They have to exist in the same DLL and the same Namespace.

    Could you elaborate a bit on what the additional data is that you are trying to pull through?

    The odds are the recommended approach would be to create your own separate classes/services for accessing the data independent of the published content models but that advise does depend on what exactly it is you are attempting to achieve.

    Nik

  • Luuk Peters 84 posts 325 karma points
    Dec 07, 2022 @ 11:04
    Luuk Peters
    0

    When creating packages, don't use the models from the models builder at all. I've tried this recently, but it will simply not work. There is a lot of startup logic in Umbraco that checks the models. If you have a model originally build by the models builder in your packages and your target project builds it's own models, it will not work. Umbraco will not even start. Also, what model should it take if the page got extra fields in your target project?

    So in the end I don't include any models in my packages that were build by the models builder.

Please Sign in or register to post replies

Write your reply to:

Draft