Currently have an strange issue, because i can't extend my "NewsArticle" model, maybe it's me that is doing it wrong..
Because i have an doc type named "News Article", which have inherited the doc type "News Meta", in the "News Meta" i have an heading field which i want to extend but when i regenerate my models it won't stop generating the heading field, which means i get this error,
The type 'NewsArticle' already contains a definition for 'NewsHeading'
The generated field looks like this,
///<summary>
/// Overskrift
///</summary>
[ImplementPropertyType("newsHeading")]
public string NewsHeading
{
get { return ProjectName.Core.Models.NewsMeta.GetNewsHeading(this); }
}
And the code i have written looks like this,
[ImplementPropertyType("newsHeading")]
public string NewsHeading
{
get
{
string newsHeading = NewsMeta.GetNewsHeading(this);
if (string.IsNullOrWhiteSpace(newsHeading))
{
newsHeading = OpenGraphSharing.GetOgTitle(this);
if (string.IsNullOrWhiteSpace(newsHeading))
{
newsHeading = SEO.GetMetaTitle(this);
if (string.IsNullOrWhiteSpace(newsHeading))
{
newsHeading = this.Name;
}
}
}
return newsHeading;
}
}
The funny part is i have done the same thing with many other thing which works, but they didn't have inherited doc types?
Extending Models
Hi Our,
Currently have an strange issue, because i can't extend my "NewsArticle" model, maybe it's me that is doing it wrong..
Because i have an doc type named "News Article", which have inherited the doc type "News Meta", in the "News Meta" i have an heading field which i want to extend but when i regenerate my models it won't stop generating the heading field, which means i get this error,
The type 'NewsArticle' already contains a definition for 'NewsHeading'
The generated field looks like this,
And the code i have written looks like this,
The funny part is i have done the same thing with many other thing which works, but they didn't have inherited doc types?
Hi Andres,
Looking at the code I think you are using a composition. Not inheritance? Is that correct.
The news article generated class will probably implement a interface called INewsMeta.
So if you go in the Newsmeta generated file you will see a interface INewsMeta and a class NewsMeta which implements the interface
So what you want to do is create a partial class called NewsMeta
In that you will add a property
And add a static method called GetNewsHeading
After these changes regenerate your models.
Dave
Hi Dave :)
Of course i'm using composition but it's friday ;)
Will try and see if this works, thanks alot! :)
Okay it's not working ..
Now my NewsHeading has been removed from the generated NewsArticle .. :(
Is the NewsArticle still implementing the INewsMeta interface ?
What happens if you remove this from your own class
And only leave the GetNewsHeading
Dave
Hi Dave :)
I have a question related to this :)
What about if i want to get the node's name in the model when i do the composition in Umbraco 8? :)
Because i can't find the .Name on that? :)
I just tested that on a project that is the trick.
In your own partial class you only need to have the GetNewsHeading method.
Than it will work.
Dave
Nice thanks alot, it worked! :)
is working on a reply...