Nhibernate Issues - Invalid Collumn?

Topics: Customizing Orchard, Troubleshooting, Writing modules
Jan 15, 2014 at 11:08 AM
Basically followed this tutorial since a few months ago to create custom modules:

However, I sporadically encounter System.Data.SqlClient.SqlException (0x80131904): Invalid column name in the logs related to these modules. They don't really stop the Content Items and their Parts from rendering, but I just feel load times / queries are taking longer because a lot of these errors are being thrown.

Below is an example that attaches a Speaker Part to a Content Item. These are some errors I get:
NHibernate.AdoNet.AbstractBatcher - Could not execute query: SELECT speakers0_.SpeakerPartRecord_id as SpeakerP8_1_, speakers0_.Id as Id1_, speakers0_.Id as Id61_0_, speakers0_.Position as Position61_0_, speakers0_.SpeakerPartId as SpeakerP3_61_0_, speakers0_.Name as Name61_0_, speakers0_.Role as Role61_0_, speakers0_.ProfileImage as ProfileI6_61_0_, speakers0_.ProfileUrl as ProfileUrl61_0_ FROM Provoke_Speakers_SpeakerInformationRecord speakers0_ WHERE speakers0_.SpeakerPartRecord_id=@p0
System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'SpeakerPartRecord_id'.

NHibernate.Util.ADOExceptionReporter - Invalid column name 'SpeakerPartRecord_id'.
    public class SpeakerPartRecord : ContentPartRecord
        public virtual IList<SpeakerInformationRecord> Speakers { get; set; } 

    public class SpeakerPart : ContentPart<SpeakerPartRecord>
        public IList<SpeakerInformationRecord> Speakers
            get { return Record.Speakers; }

    public class SpeakerInformationRecord
        public virtual int Id { get; set; }
        public virtual int Position { get; set; }
        public virtual int SpeakerPartId { get; set; }
        public virtual string Name { get; set; }
        public virtual string Role { get; set; }
        public virtual string ProfileImage { get; set; }
        public virtual string ProfileUrl { get; set; }
            // Creating table SpeakerInformationRecord
            SchemaBuilder.CreateTable("SpeakerInformationRecord", table => table
                .Column("Id", DbType.Int32, column => column.PrimaryKey().Identity())
                .Column("SpeakerPartId", DbType.Int32)
                .Column("Name", DbType.String)
                .Column("Role", DbType.String)
                .Column("ProfileImage", DbType.String)
                .Column("ProfileUrl", DbType.String)
                .Column("Position", DbType.Int32)

            // Creating table SpeakerPartRecord
            SchemaBuilder.CreateTable("SpeakerPartRecord", table => table

            ContentDefinitionManager.AlterPartDefinition("SpeakerPart", builder => builder.Attachable());
    public class SpeakerService : ISpeakerService
        private readonly IRepository<SpeakerInformationRecord> _speakerInformationRepository;
        public SpeakerService(IRepository<SpeakerInformationRecord> speakerInformationRepository)
            _speakerInformationRepository = speakerInformationRepository;

        public void UpdateSpeakersForContentItem(ContentItem item, IEnumerable<SpeakerInformationRecord> speakers)
            var record = item.As<SpeakerPart>().Record;
            var oldSpeakers = _speakerInformationRepository.Fetch(s => s.SpeakerPartId == record.Id);
            foreach (var oldSpeaker in oldSpeakers)

            foreach (var speaker in speakers)
                speaker.SpeakerPartId = record.Id;

        public IList<SpeakerInformationRecord> GetSpeakersForContentItem(ContentItem item)
            var speakerPart = item.As<SpeakerPart>();
            if (speakerPart != null)
                return _speakerInformationRepository.Fetch(s => s.SpeakerPartId == speakerPart.Id).ToList();

            return null;
Any ideas? Any piece of advise or help would be greatly appreciated. Thanks!
Jan 20, 2014 at 4:57 PM
If you compare your code to the example like the URL, your saving a list of SpeakerInformationRecord instead of one at a time, which will cause this issue.