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
    Sep 08, 2023 @ 07:43
    Daniel Rogers
    0

    connecting content in my models

    Im using Umbraco 12.

    Back in v8 i could do the things like this

            [TableName("ExypnosSalesContent")]
            [PrimaryKey("Id", AutoIncrement = true)]
            [ExplicitColumns]
            public class ExypnosSalesContent
            {
                [PrimaryKeyColumn(AutoIncrement = true, IdentitySeed = 1)]
                [Column("id")]
                public int Id { get; set; }
                [Column("productId")]
                public int ProductId { get; set; }
                [Column("variantKey")]
                public Guid VariantKey { get; set; }
                public string? ProductName { 
                    get {
                        IPublishedContent product = Umbraco.Content(this.ProductId);
    
                        return product.Name;
                    } 
                }
            }
    

    However in v12 I cant figure out how to do this.

    This is what I have

       public class ExypnosSalesContentAddTable : MigrationBase
        {
            private readonly IScopeProvider _scopeProvider;
            private readonly IPublishedContentQuery _publishedContentQuery;
    
            public ExypnosSalesContentAddTable(IMigrationContext context, 
                IScopeProvider scopeProvider,
                IPublishedContentQuery publishedContentQuery) : base(context)
            {
                _scopeProvider = scopeProvider;
                _publishedContentQuery = publishedContentQuery;
            }
    
            [TableName("ExypnosSalesContent")]
            [PrimaryKey("Id", AutoIncrement = true)]
            [ExplicitColumns]
            public class ExypnosSalesContent
            {
                [PrimaryKeyColumn(AutoIncrement = true, IdentitySeed = 1)]
                [Column("id")]
                public int Id { get; set; }
                [Column("productId")]
                public int ProductId { get; set; }
                public string? ProductName { 
                    get {
                        IPublishedContent product = _publishedContentQuery.Content(this.ProductId);
    
                        return product.Name;
                    } 
                }
            }
        }
    

    _PublisherContentQuery is not null here

    error

    CS0120 object referance is required for non-static field, methos or property

    How do I do this in v12

Please Sign in or register to post replies

Write your reply to:

Draft