AutoMappings Issues

Topics: Customizing Orchard, Writing modules
Mar 29, 2011 at 5:47 AM

  I'm getting the "An association from the table XXX refers to an unmapped class: XXX" error.  I'm familiar with NHibernate and FluentNHibernate but only with manual mapping (not so much with automapping).  Here's my code so far:

 

public class Entity1 : ContentPart<Entity1Record>
{
  public virtual Entity2 Entity2
  {
    get { return Record.Entity2; }
    set { Record.Entity2 = value; }
   }
}

public class Entity2: ContentPart<Entity2Record> 
{
    private IList<Entity1> _parts;

    public Entity2() {
        _parts = new List<Entity1>();
    }

    public virtual IList<Entity1> Entity1 
    {
        get { return _parts; }
        set { _parts = value; }
    }
}

public class Entity1Record: ContentPartRecord
{
     public virtual Entity2 Entity2{ get; set; }
}

public class Entity2Record: ContentPartRecord
{
    public virtual Entity1 Entity1 { get; set; }
}

 

  For some reason, Entity2 refuses to get picked up by FluentNHibernate.  I know I'm missing something extremely obvious.  Also, my understanding of when to designate objects to inherit from ContentPart<T> and ContentPartRecord is vary hazy.  Any guidelines on that would be appreciated.  The documentation I've read so far hasn't really cleared that up for me.

Thanks for any help!

Mar 30, 2011 at 3:09 AM

Nobody is having issues with automapping?

Coordinator
Mar 30, 2011 at 7:37 AM

You might want to make those entity references lazy.

Mar 30, 2011 at 8:16 AM

If you're linking to another entity on a ContentPartRecord, shouldn't that entity also be a *record* - not a Part? Records are mapped classed, Parts are not.  Hence "refers to an unmapped class" ;)

Coordinator
Mar 30, 2011 at 10:34 PM

Good point :)

Apr 1, 2011 at 4:45 AM

Of course! I knew it was something very obvious.  I'm still trying to get the hang of this.  I appreciate the replies.

Apr 1, 2011 at 7:32 AM

Easy one to miss ;) Just to clear up the other part of your question, a ContentPartRecord is the backing class for a ContentPart<TRecord>. So if you have MyDbPartRecord then you also have MyDbPart<MyDbPartRecord>. The Record should only contain the properties needed to persist your object in the database; whereas the Part itself may have other properties that you actually need in your view.

Nov 19, 2011 at 4:27 PM
Edited Nov 19, 2011 at 4:28 PM

Having the same issue with AutoMapping

The error:

An association from the table Seminars_SeminarPartRecord refers to an unmapped class: Seminars.Models.TopicsRecord

 

My Code:

 

 

using System;
using System.Collections.Generic;
using System.Web;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Records;
using Seminars.Models;
using FluentNHibernate;


/// <summary>
/// Summary description for ClassName
/// </summary>
namespace Seminars.Models
{

      public class SeminarPart : ContentPart<SeminarPartRecord>
    {
        public string Topic
        {

            get {return Record.Topic; }
            set {Record.Topic = value; }
        }

         public TopicsRecord Topics
         {

              get { return Record.TopicsRecord; }
              set { Record.TopicsRecord = value; }

          }       

        
    }

   public class SeminarPartRecord : ContentPartRecord
   {

       public virtual string Topic { get; set; }

       public virtual TopicsRecord TopicsRecord { get; set; }



   }

  
}


The TopicsRecord Class:

using System;
using System.Collections.Generic;
using System.Web;
using Orchard.ContentManagement.Records;
using FluentNHibernate;

/// <summary>
/// Summary description for ClassName
/// </summary>
namespace Seminars.Models
{
    public class TopicsRecord
    {
        public virtual string  TopicCode { get; set; }

        public virtual string BrochureDesc { get; set; }

        public virtual string URL { get; set; }

        public virtual double ControlPrice { get; set; }

        public virtual int GroupNumber { get; set; }

        public virtual double GroupPrice { get; set; }

        public virtual string Brand { get; set; }

        public virtual string Country { get; set; }
    }

}

The Migration File:

using System;
using System.Collections.Generic;
using System.Data;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;
using FluentNHibernate;

namespace Seminars {
    public class Migrations : DataMigrationImpl {

        public int Create() {
         SchemaBuilder.CreateTable("SeminarPartRecord",
            table => table
            .ContentPartRecord()
            .Column<string>("Topic")
            .Column<string>("TopicsRecord_TopicCode")
        );

          SchemaBuilder.CreateTable("TopicsRecord", table => table
            .Column<string>("TopicCode", column => column.PrimaryKey().Identity())
            .Column<string>("BrochureDesc")
            .Column<string>("URL")
            .Column<double>("ControlPrice")
            .Column<int>("GroupNumber")
            .Column<double>("GroupPrice")
            .Column<string>("Brand")
            .Column<string>("Country")
            );


        ContentDefinitionManager.AlterPartDefinition("SeminarPart",
        builder => builder.Attachable());

            return 1;
        }
    }
}


Coordinator
Nov 19, 2011 at 4:34 PM

TopicsRecord needs an Id, or won't be automapped.

Nov 19, 2011 at 5:30 PM

Thank you. Does the Id column have to be the primary key? I am migrating data into that new table using SQL Management Studio.  The table I am migrating from does not have an Id column.

Coordinator
Nov 19, 2011 at 9:41 PM

Yes.