You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to create a taxonomy programatically during a migration based on code I saw in issue #3721 where @barthamark used the following code:
public async Task<int> CreateAsync()
{
...
var taxonomy = await _contentManager.NewAsync("Taxonomy");
taxonomy.DisplayText = "My Taxonomy";
var taxonomyPart = taxonomy.As<TaxonomyPart>(); // taxonomyPart is null for me
taxonomyPart.TermContentType = "MyTermType";
taxonomy = taxonomy.Apply(taxonomyPart);
await _contentManager.CreateAsync(taxonomy, VersionOptions.Published);
...
It was throwing an exception but there was some new code at the time (about 5 years ago) and apparently then it just started working. A couple experienced Orchard develoeprs, including @sebastienros, commented on that post so I assumed it was an ok approach... at least at that time, again, ~5 years ago. The above code doesn't work for me. On the taxonomy.As() line, taxonomyPart is null for me. Sure enough, when I look at the content definitions, the TaxonomyPart is not added to the Taxonomy content type. Has something changed or am I just missing something? Should the above work?
Orchard Core version
2.1.5
To Reproduce
Create a new Orchard Core site.
Expected behavior
Taxonomy has TaxonomyPart.
The text was updated successfully, but these errors were encountered:
Do you have the Taxonomies feature enabled? Is it set as a dependency to your module/feature in the Manifest.cs file? Maybe the Taxonomies feature is enabled later in the pipeline and that's where the part would be added; adding it as a dependency might fix it if it's not already there.
Wow. @barthamark thank you so much! That was it. I did have taxonomies enabled but my manifest dependency was wrong. I had brilliantly put in the singlular Taxonomy instead of plural Taxonomies. I guess it is time to create some constants for those strings... or maybe I'll just start using something like $"{nameof(OrchardCore)}.{nameof(OrchardCore.Taxonomies)}" for the dependency declaration.
I've come back to this a few times over the years and could never make it work or find the right help. I didn't realize how important those dependencies in the manifest are. I always felt it was kind of weird because I already have to add the nuget OrchardCore.Taxonomies packages and the taxonomy type generally seemed to be working just fine - my workaround of just creating the taxonomy by executing a recipe as my first step had always been just fine. Thanks again!
I'm trying to create a taxonomy programatically during a migration based on code I saw in issue #3721 where @barthamark used the following code:
It was throwing an exception but there was some new code at the time (about 5 years ago) and apparently then it just started working. A couple experienced Orchard develoeprs, including @sebastienros, commented on that post so I assumed it was an ok approach... at least at that time, again, ~5 years ago. The above code doesn't work for me. On the taxonomy.As() line, taxonomyPart is null for me. Sure enough, when I look at the content definitions, the TaxonomyPart is not added to the Taxonomy content type. Has something changed or am I just missing something? Should the above work?
Orchard Core version
2.1.5
To Reproduce
Create a new Orchard Core site.
Expected behavior
Taxonomy has TaxonomyPart.
The text was updated successfully, but these errors were encountered: