Exception saving a new content item with Taxonomy field

Topics: Core, Writing modules
Feb 18, 2014 at 10:00 PM
Edited Feb 18, 2014 at 10:02 PM
I've created a new ContentType/Part, and added a new Field of type Taxonomy by code using Migrations.

When I hit "Save" or "Publish" on the ContentItem, I get the exception shown in the attached image.

Any idea what's might be going on?

Thanks

http://screencast.com/t/E7k6M2UdQbyn
Coordinator
Feb 19, 2014 at 5:10 AM
A little more information, such as your migration code, might help...
Feb 19, 2014 at 9:11 AM
Before adding the Taxonomy field, I was able to save and publish the content item.

Here is the migration code:
public int UpdateFrom4()
        {
            ContentDefinitionManager.AlterPartDefinition("MoviePart", builder =>
                builder.WithField("Genre", fld =>
                    fld.OfType("TaxonomyField")
                    .WithSetting("DisplayName", "Genre")
                    .WithSetting("TaxonomyFieldSettings.Taxonomy", "Genre")
                    .WithSetting("TaxonomyFieldSettings.LeavesOnly", "False")
                    .WithSetting("TaxonomyFieldSettings.SingleChoice", "False")
                    .WithSetting("TaxonomyFieldSettings.Hint", "Select as many genres as apply to this movie.")));
            return 5;
        }
That was the last update I did on the Migration.

And I used a FeatureEventHandler to create the Taxonomy and Terms values as follows:
using Orchard.ContentManagement;
using Orchard.Core.Common.Models;
using Orchard.Environment;
using Orchard.Environment.Extensions.Models;
using Orchard.Taxonomies.Models;
using Orchard.Taxonomies.Services;

namespace Pluralsight.Movies.Handlers {
    public class MovieFeatureEventHandler : IFeatureEventHandler {
        private readonly ITaxonomyService _taxonomyService;
        private readonly IContentManager _contentManager;

        public MovieFeatureEventHandler(ITaxonomyService taxonomyService,
            IContentManager contentManager) {
            _taxonomyService = taxonomyService;
            _contentManager = contentManager;
        }

        public void Installing(Feature feature) {
        }

        public void Installed(Feature feature) {
        }

        public void Enabling(Feature feature) {
        }

        public void Enabled(Feature feature) {
            // if Genre taxonomy does not exist
            //    create Genre taxonomy
            //    create several genre terms in the taxonomy
            if (_taxonomyService.GetTaxonomyByName("Genre") == null) {
                
                // Instantiate a new ContentItem of ContentType "Taxonomy" 
                // with return type "TaxonomyPart"
                var genre = _contentManager.New<TaxonomyPart>("Taxonomy");

                // Can be casted to any ContentPart as it holds a reference to content type
                // genre.As<CommonPart>().CreatedUtc

                // Fill in the properties
                genre.Name = "Genre";

                // Save a ContentItem
                _contentManager.Create(genre, VersionOptions.Published);

                CreateTerm(genre, "Action");
                CreateTerm(genre, "Adventure");
                CreateTerm(genre, "Animation");
                CreateTerm(genre, "Comedy");
                CreateTerm(genre, "Crime");
                CreateTerm(genre, "Documentary");
                CreateTerm(genre, "Drama");
            }
        }

        private void CreateTerm(TaxonomyPart genre, string genreName) {
            var term = _taxonomyService.NewTerm(genre);
            term.Name = genreName;
            _contentManager.Create(term, VersionOptions.Published);
        }

        public void Disabling(Feature feature) {
        }

        public void Disabled(Feature feature) {
        }

        public void Uninstalling(Feature feature) {
        }

        public void Uninstalled(Feature feature) {
        }
    }
}
Thanks
Feb 19, 2014 at 9:19 AM
BTW, here's the Log info:
NHibernate.AssertionFailure: null id in Orchard.ContentManagement.Records.ContentItemVersionRecord entry (don't flush the Session after an exception occurs)
2014-02-18 23:29:15,182 [121] Orchard.Exceptions.DefaultExceptionPolicy - An unexpected exception was caught
NHibernate.Exceptions.GenericADOException: could not insert: [Orchard.ContentManagement.Records.ContentItemVersionRecord][SQL: INSERT INTO Orchard_Framework_ContentItemVersionRecord (Number, Published, Latest, Data, ContentItemRecord_id) VALUES (?, ?, ?, ?, ?)] ---> System.Data.SqlServerCe.SqlCeLockTimeoutException: SQL Server Compact timed out waiting for a lock. The default lock time is 2000ms for devices and 5000ms for desktops. The default lock timeout can be increased in the connection string using the ssce: default lock timeout property. [ Session id = 2,Thread id = 1328,Process id = 9196,Table name = Orchard_Framework_ContentItemVersionRecord,Conflict type = x lock (x blocks),Resource = PAG (idx): 1069 ]
   at System.Data.SqlServerCe.SqlCeCommand.ProcessResults(Int32 hr)
   at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommandText(IntPtr& pCursor, Boolean& isBaseTableCursor)
   at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options)
   at System.Data.SqlServerCe.SqlCeCommand.ExecuteNonQuery()
   at NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\AdoNet\AbstractBatcher.cs:line 203
   at NHibernate.Id.Insert.AbstractSelectingDelegate.PerformInsert(SqlCommandInfo insertSQL, ISessionImplementor session, IBinder binder) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Id\Insert\AbstractSelectingDelegate.cs:line 38
   --- End of inner exception stack trace ---
   at NHibernate.Id.Insert.AbstractSelectingDelegate.PerformInsert(SqlCommandInfo insertSQL, ISessionImplementor session, IBinder binder) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Id\Insert\AbstractSelectingDelegate.cs:line 47
   at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Boolean[] notNull, SqlCommandInfo sql, Object obj, ISessionImplementor session) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs:line 2575
   at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Object obj, ISessionImplementor session) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs:line 3035
   at NHibernate.Action.EntityIdentityInsertAction.Execute() in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Action\EntityIdentityInsertAction.cs:line 75
   at NHibernate.Engine.ActionQueue.Execute(IExecutable executable) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Engine\ActionQueue.cs:line 136
   at NHibernate.Event.Default.AbstractSaveEventListener.PerformSaveOrReplicate(Object entity, EntityKey key, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\AbstractSaveEventListener.cs:line 259
   at NHibernate.Event.Default.AbstractSaveEventListener.PerformSave(Object entity, Object id, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\AbstractSaveEventListener.cs:line 187
   at NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\AbstractSaveEventListener.cs:line 119
   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultSaveOrUpdateEventListener.cs:line 162
   at NHibernate.Event.Default.DefaultSaveEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultSaveEventListener.cs:line 27
   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultSaveOrUpdateEventListener.cs:line 148
   at NHibernate.Event.Default.DefaultSaveEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultSaveEventListener.cs:line 21
   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultSaveOrUpdateEventListener.cs:line 53
   at NHibernate.Impl.SessionImpl.FireSave(SaveOrUpdateEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\SessionImpl.cs:line 2673
   at NHibernate.Impl.SessionImpl.Save(Object obj) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\SessionImpl.cs:line 485
   at Orchard.Data.Repository`1.Create(T entity) in d:\Dev\Repos\orchardfeb\src\Orchard\Data\Repository.cs:line 96
   at Orchard.Data.Repository`1.Orchard.Data.IRepository<T>.Create(T entity) in d:\Dev\Repos\orchardfeb\src\Orchard\Data\Repository.cs:line 36
   at Orchard.ContentManagement.DefaultContentManager.BuildNewVersion(ContentItem existingContentItem) in d:\Dev\Repos\orchardfeb\src\Orchard\ContentManagement\DefaultContentManager.cs:line 461
   at Orchard.ContentManagement.DefaultContentManager.Get(Int32 id, VersionOptions options, QueryHints hints) in d:\Dev\Repos\orchardfeb\src\Orchard\ContentManagement\DefaultContentManager.cs:line 213
   at Orchard.ContentManagement.DefaultContentManager.Get(Int32 id, VersionOptions options) in d:\Dev\Repos\orchardfeb\src\Orchard\ContentManagement\DefaultContentManager.cs:line 131
   at Orchard.Core.Contents.Controllers.AdminController.EditPOST(Int32 id, String returnUrl, Action`1 conditionallyPublish) in d:\Dev\Repos\orchardfeb\src\Orchard.Web\Core\Contents\Controllers\AdminController.cs:line 292
   at Orchard.Core.Contents.Controllers.AdminController.EditAndPublishPOST(Int32 id, String returnUrl) in d:\Dev\Repos\orchardfeb\src\Orchard.Web\Core\Contents\Controllers\AdminController.cs:line 288
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass13.<InvokeActionMethodWithFilters>b__10()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass13.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass13.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
Feb 19, 2014 at 9:23 AM
Edited Feb 19, 2014 at 9:23 AM
Even, when I try now to delete an old "Movie" that was created before adding the "Taxonomy" field, I get this exception and item not being deleted:
2014-02-19 11:21:15,924 [9] Orchard.ContentManagement.DefaultContentManager - GenericADOException thrown from IContentHandler by Orchard.Indexing.Handlers.CreateIndexingTaskHandler
NHibernate.Exceptions.GenericADOException: could not insert: [Orchard.Indexing.Models.IndexingTaskRecord][SQL: INSERT INTO Orchard_Indexing_IndexingTaskRecord (Action, CreatedUtc, ContentItemRecord_id) VALUES (?, ?, ?)] ---> System.Data.SqlServerCe.SqlCeLockTimeoutException: SQL Server Compact timed out waiting for a lock. The default lock time is 2000ms for devices and 5000ms for desktops. The default lock timeout can be increased in the connection string using the ssce: default lock timeout property. [ Session id = 2,Thread id = 9036,Process id = 6776,Table name = Orchard_Indexing_IndexingTaskRecord,Conflict type = x lock (x blocks),Resource = PAG (idx): 1323 ]
   at System.Data.SqlServerCe.SqlCeCommand.ProcessResults(Int32 hr)
   at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommandText(IntPtr& pCursor, Boolean& isBaseTableCursor)
   at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options)
   at System.Data.SqlServerCe.SqlCeCommand.ExecuteNonQuery()
   at NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\AdoNet\AbstractBatcher.cs:line 203
   at NHibernate.Id.Insert.AbstractSelectingDelegate.PerformInsert(SqlCommandInfo insertSQL, ISessionImplementor session, IBinder binder) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Id\Insert\AbstractSelectingDelegate.cs:line 38
   --- End of inner exception stack trace ---
   at NHibernate.Id.Insert.AbstractSelectingDelegate.PerformInsert(SqlCommandInfo insertSQL, ISessionImplementor session, IBinder binder) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Id\Insert\AbstractSelectingDelegate.cs:line 47
   at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Boolean[] notNull, SqlCommandInfo sql, Object obj, ISessionImplementor session) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs:line 2575
   at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Object obj, ISessionImplementor session) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs:line 3035
   at NHibernate.Action.EntityIdentityInsertAction.Execute() in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Action\EntityIdentityInsertAction.cs:line 75
   at NHibernate.Engine.ActionQueue.Execute(IExecutable executable) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Engine\ActionQueue.cs:line 136
   at NHibernate.Event.Default.AbstractSaveEventListener.PerformSaveOrReplicate(Object entity, EntityKey key, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\AbstractSaveEventListener.cs:line 259
   at NHibernate.Event.Default.AbstractSaveEventListener.PerformSave(Object entity, Object id, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\AbstractSaveEventListener.cs:line 187
   at NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\AbstractSaveEventListener.cs:line 119
   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultSaveOrUpdateEventListener.cs:line 162
   at NHibernate.Event.Default.DefaultSaveEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultSaveEventListener.cs:line 27
   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultSaveOrUpdateEventListener.cs:line 148
   at NHibernate.Event.Default.DefaultSaveEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultSaveEventListener.cs:line 21
   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultSaveOrUpdateEventListener.cs:line 53
   at NHibernate.Impl.SessionImpl.FireSave(SaveOrUpdateEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\SessionImpl.cs:line 2673
   at NHibernate.Impl.SessionImpl.Save(Object obj) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\SessionImpl.cs:line 485
   at Orchard.Data.Repository`1.Create(T entity) in d:\Dev\Repos\orchardfeb\src\Orchard\Data\Repository.cs:line 96
   at Orchard.Data.Repository`1.Orchard.Data.IRepository<T>.Create(T entity) in d:\Dev\Repos\orchardfeb\src\Orchard\Data\Repository.cs:line 36
   at Orchard.Indexing.Services.IndexingTaskManager.CreateTask(ContentItem contentItem, Int32 action)
   at Orchard.Indexing.Services.IndexingTaskManager.CreateDeleteIndexTask(ContentItem contentItem)
   at Orchard.Indexing.Handlers.CreateIndexingTaskHandler.RemoveIndexingTask(RemoveContentContext context, ContentPart part)
   at Orchard.ContentManagement.Handlers.ContentHandler.InlineStorageFilter`1.Removed(RemoveContentContext context, TPart instance) in d:\Dev\Repos\orchardfeb\src\Orchard\ContentManagement\Handlers\ContentHandler.cs:line 176
   at Orchard.ContentManagement.Handlers.StorageFilterBase`1.Orchard.ContentManagement.Handlers.IContentStorageFilter.Removed(RemoveContentContext context) in d:\Dev\Repos\orchardfeb\src\Orchard\ContentManagement\Handlers\StorageFilterBase.cs:line 107
   at Orchard.ContentManagement.Handlers.ContentHandler.Orchard.ContentManagement.Handlers.IContentHandler.Removed(RemoveContentContext context) in d:\Dev\Repos\orchardfeb\src\Orchard\ContentManagement\Handlers\ContentHandler.cs:line 312
   at Orchard.ContentManagement.DefaultContentManager.<>c__DisplayClass4b.<Remove>b__4a(IContentHandler handler) in d:\Dev\Repos\orchardfeb\src\Orchard\ContentManagement\DefaultContentManager.cs:line 434
   at Orchard.InvokeExtensions.Invoke[TEvents](IEnumerable`1 events, Action`1 dispatch, ILogger logger) in d:\Dev\Repos\orchardfeb\src\Orchard\InvokeExtensions.cs:line 17
2014-02-19 11:21:15,952 [9] NHibernate.AssertionFailure - An AssertionFailure occurred - this may indicate a bug in NHibernate or in your custom types.
NHibernate.AssertionFailure: null id in Orchard.Indexing.Models.IndexingTaskRecord entry (don't flush the Session after an exception occurs)
2014-02-19 11:21:15,953 [9] Orchard.ContentManagement.DefaultContentManager - AssertionFailure thrown from IContentHandler by Orchard.Autoroute.Handlers.AutoroutePartHandler
NHibernate.AssertionFailure: null id in Orchard.Indexing.Models.IndexingTaskRecord entry (don't flush the Session after an exception occurs)
   at NHibernate.Event.Default.DefaultFlushEntityEventListener.CheckId(Object obj, IEntityPersister persister, Object id, EntityMode entityMode) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultFlushEntityEventListener.cs:line 111
   at NHibernate.Event.Default.DefaultFlushEntityEventListener.GetValues(Object entity, EntityEntry entry, EntityMode entityMode, Boolean mightBeDirty, ISessionImplementor session) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultFlushEntityEventListener.cs:line 77
   at NHibernate.Event.Default.DefaultFlushEntityEventListener.OnFlushEntity(FlushEntityEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultFlushEntityEventListener.cs:line 36
   at NHibernate.Event.Default.AbstractFlushingEventListener.FlushEntities(FlushEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\AbstractFlushingEventListener.cs:line 161
   at NHibernate.Event.Default.AbstractFlushingEventListener.FlushEverythingToExecutions(FlushEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\AbstractFlushingEventListener.cs:line 60
   at NHibernate.Event.Default.DefaultAutoFlushEventListener.OnAutoFlush(AutoFlushEvent event) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Event\Default\DefaultAutoFlushEventListener.cs:line 30
   at NHibernate.Impl.SessionImpl.AutoFlushIfRequired(ISet`1 querySpaces) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\SessionImpl.cs:line 1182
   at NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\SessionImpl.cs:line 647
   at NHibernate.Impl.AbstractSessionImpl.List(IQueryExpression queryExpression, QueryParameters parameters) in c:\Users\sebros\Documents\My Projects\nhibernate-core\src\NHibernate\Impl\AbstractSessionImpl.cs:line 92
Feb 24, 2014 at 1:40 PM
Any help please?

Regards
Bilal
Coordinator
Feb 27, 2014 at 8:24 PM
Creating a taxonomy term is not "that" simple as it requires new types to be created dynamically too. These are created using specific services in the TaxonomyService class.

Your best shot would be to look at the taxonomy import code which does that, or to use a Recipe file to create them. You can have a recipe file by just exporting the data and metadata, and put this recipe in the /Recipes folder of your module. Look at what the Orchard.Search/Recipes folder contains.
Feb 27, 2014 at 8:29 PM
Thanks Sebastien a lot for your prompt answer! really appreciate it. I will check the ideas you mentioned above. Thanks
Feb 27, 2014 at 8:57 PM
Hello,
I've added this file to the /Recipes folder of my module, deleted the DB and started all over the setup. The Taxonomy is not being created. Anything wrong with the Recipe file? Thanks
<Orchard>
  <Recipe>
    <Name>PluralsightMovies</Name>
    <Author>Bilal Haidar</Author>
  </Recipe>

  <Module packageId="Pluralsight.Movies" />

  <Feature enable="Pluralsight.Movies" />

  <Settings />

  <Migration features="*" />
  
  <Metadata>
    <Types>
      <GenreTerm Taxonomy="Genre" DisplayName="Genre Term">
        <TermPart />
        <TitlePart />
        <AutoroutePart AutorouteSettings.AllowCustomPattern="true" AutorouteSettings.AutomaticAdjustmentOnEdit="false" AutorouteSettings.PatternDefinitions="[{Name:'Taxonomy and Title', Pattern: '{Content.Container.Path}/{Content.Slug}', Description: 'my-taxonomy/my-term/sub-term'}]" AutorouteSettings.DefaultPatternIndex="0" />
        <CommonPart />
      </GenreTerm>
    </Types>
    <Parts>
      <TermPart />
      <TitlePart ContentPartSettings.Attachable="True" ContentPartSettings.Description="Provides a Title for your content item." />
      <AutoroutePart ContentPartSettings.Attachable="True" ContentPartSettings.Description="Adds advanced url configuration options to your content type to completely customize the url pattern for a content item." />
      <CommonPart ContentPartSettings.Attachable="True" ContentPartSettings.Description="Provides common information about a content item, such as Owner, Date Created, Date Published and Date Modified." />
    </Parts>
  </Metadata>

  <Data>
    <GenreTerm Id="/alias=genre\/action" Status="Published">
      <CommonPart Owner="/User.UserName=admin" Container="/alias=genre" CreatedUtc="2014-02-27T20:42:19Z" PublishedUtc="2014-02-27T20:42:19Z" ModifiedUtc="2014-02-27T20:42:19Z" />
      <AutoroutePart Alias="genre/action" UseCustomPattern="false" />
      <TitlePart Title="Action" />
      <TermPart Count="0" Selectable="true" Weight="0" TaxonomyId="/alias=genre" Path="" />
    </GenreTerm>
    <GenreTerm Id="/alias=genre\/adventure" Status="Published">
      <CommonPart Owner="/User.UserName=admin" Container="/alias=genre" CreatedUtc="2014-02-27T20:42:31Z" PublishedUtc="2014-02-27T20:42:31Z" ModifiedUtc="2014-02-27T20:42:31Z" />
      <AutoroutePart Alias="genre/adventure" UseCustomPattern="false" />
      <TitlePart Title="Adventure" />
      <TermPart Count="0" Selectable="true" Weight="0" TaxonomyId="/alias=genre" Path="" />
    </GenreTerm>
    <GenreTerm Id="/alias=genre\/animation" Status="Published">
      <CommonPart Owner="/User.UserName=admin" Container="/alias=genre" CreatedUtc="2014-02-27T20:42:41Z" PublishedUtc="2014-02-27T20:42:41Z" ModifiedUtc="2014-02-27T20:42:41Z" />
      <AutoroutePart Alias="genre/animation" UseCustomPattern="false" />
      <TitlePart Title="Animation" />
      <TermPart Count="0" Selectable="true" Weight="0" TaxonomyId="/alias=genre" Path="" />
    </GenreTerm>
    <GenreTerm Id="/alias=genre\/comedy" Status="Published">
      <CommonPart Owner="/User.UserName=admin" Container="/alias=genre" CreatedUtc="2014-02-27T20:42:50Z" PublishedUtc="2014-02-27T20:42:50Z" ModifiedUtc="2014-02-27T20:42:50Z" />
      <AutoroutePart Alias="genre/comedy" UseCustomPattern="false" />
      <TitlePart Title="Comedy" />
      <TermPart Count="0" Selectable="true" Weight="0" TaxonomyId="/alias=genre" Path="" />
    </GenreTerm>
    <GenreTerm Id="/alias=genre\/crime" Status="Published">
      <CommonPart Owner="/User.UserName=admin" Container="/alias=genre" CreatedUtc="2014-02-27T20:43:06Z" PublishedUtc="2014-02-27T20:43:07Z" ModifiedUtc="2014-02-27T20:43:06Z" />
      <AutoroutePart Alias="genre/crime" UseCustomPattern="false" />
      <TitlePart Title="Crime" />
      <TermPart Count="0" Selectable="true" Weight="0" TaxonomyId="/alias=genre" Path="" />
    </GenreTerm>
    <GenreTerm Id="/alias=genre\/documentary" Status="Published">
      <CommonPart Owner="/User.UserName=admin" Container="/alias=genre" CreatedUtc="2014-02-27T20:43:16Z" PublishedUtc="2014-02-27T20:43:16Z" ModifiedUtc="2014-02-27T20:43:16Z" />
      <AutoroutePart Alias="genre/documentary" UseCustomPattern="false" />
      <TitlePart Title="Documentary" />
      <TermPart Count="0" Selectable="true" Weight="0" TaxonomyId="/alias=genre" Path="" />
    </GenreTerm>
    <GenreTerm Id="/alias=genre\/drama" Status="Published">
      <CommonPart Owner="/User.UserName=admin" Container="/alias=genre" CreatedUtc="2014-02-27T20:43:26Z" PublishedUtc="2014-02-27T20:43:26Z" ModifiedUtc="2014-02-27T20:43:26Z" />
      <AutoroutePart Alias="genre/drama" UseCustomPattern="false" />
      <TitlePart Title="Drama" />
      <TermPart Count="0" Selectable="true" Weight="0" TaxonomyId="/alias=genre" Path="" />
    </GenreTerm>
  </Data>
  
</Orchard>
Feb 27, 2014 at 9:34 PM
I updated the recipe file as follows. I ran it from the "Recipe" Tab inside "Modules" and yet Taxonomy was not created!
<Orchard>
  <Recipe>
    <Name>PluralsightMovies</Name>
    <Author>Bilal Haidar</Author>
  </Recipe>

  <Feature enable="Pluralsight.Movies" />
 
  <Migration features="*" />
  
  <Metadata>
    <Types>
      <GenreTerm Taxonomy="Genre" DisplayName="Genre Term">
        <TermPart />
        <TitlePart />
        <AutoroutePart AutorouteSettings.AllowCustomPattern="true" AutorouteSettings.AutomaticAdjustmentOnEdit="false" AutorouteSettings.PatternDefinitions="[{Name:'Taxonomy and Title', Pattern: '{Content.Container.Path}/{Content.Slug}', Description: 'my-taxonomy/my-term/sub-term'}]" AutorouteSettings.DefaultPatternIndex="0" />
        <CommonPart />
      </GenreTerm>
    </Types>
    <Parts>
      <TermPart />
      <TitlePart ContentPartSettings.Attachable="True" ContentPartSettings.Description="Provides a Title for your content item." />
      <AutoroutePart ContentPartSettings.Attachable="True" ContentPartSettings.Description="Adds advanced url configuration options to your content type to completely customize the url pattern for a content item." />
      <CommonPart ContentPartSettings.Attachable="True" ContentPartSettings.Description="Provides common information about a content item, such as Owner, Date Created, Date Published and Date Modified." />
    </Parts>
  </Metadata>

  <Data>
    <GenreTerm Id="/alias=genre\/action" Status="Published">
      <CommonPart Owner="/User.UserName=admin" Container="/alias=genre" CreatedUtc="2014-02-27T20:42:19Z" PublishedUtc="2014-02-27T20:42:19Z" ModifiedUtc="2014-02-27T20:42:19Z" />
      <AutoroutePart Alias="genre/action" UseCustomPattern="false" />
      <TitlePart Title="Action" />
      <TermPart Count="0" Selectable="true" Weight="0" TaxonomyId="/alias=genre" Path="" />
    </GenreTerm>
    <GenreTerm Id="/alias=genre\/adventure" Status="Published">
      <CommonPart Owner="/User.UserName=admin" Container="/alias=genre" CreatedUtc="2014-02-27T20:42:31Z" PublishedUtc="2014-02-27T20:42:31Z" ModifiedUtc="2014-02-27T20:42:31Z" />
      <AutoroutePart Alias="genre/adventure" UseCustomPattern="false" />
      <TitlePart Title="Adventure" />
      <TermPart Count="0" Selectable="true" Weight="0" TaxonomyId="/alias=genre" Path="" />
    </GenreTerm>
    <GenreTerm Id="/alias=genre\/animation" Status="Published">
      <CommonPart Owner="/User.UserName=admin" Container="/alias=genre" CreatedUtc="2014-02-27T20:42:41Z" PublishedUtc="2014-02-27T20:42:41Z" ModifiedUtc="2014-02-27T20:42:41Z" />
      <AutoroutePart Alias="genre/animation" UseCustomPattern="false" />
      <TitlePart Title="Animation" />
      <TermPart Count="0" Selectable="true" Weight="0" TaxonomyId="/alias=genre" Path="" />
    </GenreTerm>
    <GenreTerm Id="/alias=genre\/comedy" Status="Published">
      <CommonPart Owner="/User.UserName=admin" Container="/alias=genre" CreatedUtc="2014-02-27T20:42:50Z" PublishedUtc="2014-02-27T20:42:50Z" ModifiedUtc="2014-02-27T20:42:50Z" />
      <AutoroutePart Alias="genre/comedy" UseCustomPattern="false" />
      <TitlePart Title="Comedy" />
      <TermPart Count="0" Selectable="true" Weight="0" TaxonomyId="/alias=genre" Path="" />
    </GenreTerm>
    <GenreTerm Id="/alias=genre\/crime" Status="Published">
      <CommonPart Owner="/User.UserName=admin" Container="/alias=genre" CreatedUtc="2014-02-27T20:43:06Z" PublishedUtc="2014-02-27T20:43:07Z" ModifiedUtc="2014-02-27T20:43:06Z" />
      <AutoroutePart Alias="genre/crime" UseCustomPattern="false" />
      <TitlePart Title="Crime" />
      <TermPart Count="0" Selectable="true" Weight="0" TaxonomyId="/alias=genre" Path="" />
    </GenreTerm>
    <GenreTerm Id="/alias=genre\/documentary" Status="Published">
      <CommonPart Owner="/User.UserName=admin" Container="/alias=genre" CreatedUtc="2014-02-27T20:43:16Z" PublishedUtc="2014-02-27T20:43:16Z" ModifiedUtc="2014-02-27T20:43:16Z" />
      <AutoroutePart Alias="genre/documentary" UseCustomPattern="false" />
      <TitlePart Title="Documentary" />
      <TermPart Count="0" Selectable="true" Weight="0" TaxonomyId="/alias=genre" Path="" />
    </GenreTerm>
    <GenreTerm Id="/alias=genre\/drama" Status="Published">
      <CommonPart Owner="/User.UserName=admin" Container="/alias=genre" CreatedUtc="2014-02-27T20:43:26Z" PublishedUtc="2014-02-27T20:43:26Z" ModifiedUtc="2014-02-27T20:43:26Z" />
      <AutoroutePart Alias="genre/drama" UseCustomPattern="false" />
      <TitlePart Title="Drama" />
      <TermPart Count="0" Selectable="true" Weight="0" TaxonomyId="/alias=genre" Path="" />
    </GenreTerm>
  </Data>
  
</Orchard>
Coordinator
Feb 27, 2014 at 9:46 PM
I don't see the taxonomy in this recipe file. Did you select it during the import ?
Feb 27, 2014 at 9:48 PM

It's under Data section and also metatype shows the Genre Term no?

Thanks

Feb 27, 2014 at 10:11 PM

I got what you mean, I selected Taxonomy while exporting and now it's works well.

This is an alternative and works well.

Thanks a lot