Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Orchard Project Module getting error: No persister for: SomePartRecord

I am trying to create a simple setting in Orchard that appears in the settings page. I have created a module which is adding my ContentPart to the settings page and is correctly creating a table in the database but every time the cshtml file is rendered and the property of the record is accessed I keep getting the following NHibernate Record.

No persister for: TekFlow.Contact.TekFlowEmailSettingsPartRecord. (TekFlow.Contact is the Module name)

Below is all of the code that I am using to create the Record/Part/Handler/Driver needed in Orchard.

 public class TekFlowEmailSettingsPartDriver : ContentPartDriver<TekFlowEmailSettingsPart>
{
    public TekFlowEmailSettingsPartDriver()
    {
        T = NullLocalizer.Instance;
    }

    public Localizer T { get; set; }

    protected override DriverResult Editor(TekFlowEmailSettingsPart part, dynamic shapeHelper)
    {
        return ContentShape("Parts_TekFlowEmailSettings_Edit",
            () => shapeHelper.EditorTemplate(TemplateName: "Parts.TekFlowEmailSettings", Model: part, Prefix: Prefix)
                );
    }

    protected override DriverResult Editor(TekFlowEmailSettingsPart part, Orchard.ContentManagement.IUpdateModel updater, dynamic shapeHelper)
    {
        bool success = updater.TryUpdateModel(part, Prefix, null, null);
        return Editor(part, shapeHelper);
    }
}

[UsedImplicitly]
public class TekFlowEmailSettingsPartHandler : ContentHandler
{
    public TekFlowEmailSettingsPartHandler(IRepository<TekFlowEmailSettingsPartRecord> repository)
    {
        Filters.Add(new ActivatingFilter<TekFlowEmailSettingsPart>("Site"));
        Filters.Add(StorageFilter.For(repository));
    }
}

 public class TekFlowEmailSettingsPartRecord : ContentPartRecord {
     public virtual string SendToEmail { get; set; }
}

 public class TekFlowEmailSettingsPart : ContentPart<TekFlowEmailSettingsPartRecord>
 {
     public string SendToEmail
     {
         get { return Record.SendToEmail; }
         set { Record.SendToEmail = value; }
     }
 }

 public class TekFlowEmailSettingsDataMigration : DataMigrationImpl
 {
     public int Create()
     {
         SchemaBuilder.CreateTable("TekFlowEmailSettingsPartRecord",
             table => table
                 .ContentPartRecord()
                 .Column<string>("SendToEmail", c => c.WithDefault("[email protected]").WithLength(255))
             );


         ContentDefinitionManager.AlterPartDefinition(
             typeof(TekFlowEmailSettingsPart).Name, cfg => cfg.Attachable());

         return 1;
     }
 }
like image 230
runxc1 Bret Ferrier Avatar asked Feb 14 '11 18:02

runxc1 Bret Ferrier


2 Answers

Turns out that if your Part and Record are not in your "Models" namespace that this wont work in orchard. When I changed the Namespace for the two classes it worked. Must be an assumption that Orchard is making.

like image 122
runxc1 Bret Ferrier Avatar answered Nov 16 '22 20:11

runxc1 Bret Ferrier


I got the same error from not having virtual variables in my record. (In my case it did not inherit ContentPartRecord and declared it's own Id, not sure if the issue simply was that Id was not virtual or that all variables had to be virtual.)

Also as mentioned above your namespace must end with Models or Records, as explained here: https://orchard.codeplex.com/discussions/267968

like image 2
Søren Ullidtz Avatar answered Nov 16 '22 22:11

Søren Ullidtz