Orchard Project Module getting error: No persister for: SomePartRecord
Asked Answered
L

3

6

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;
     }
 }
Lyudmila answered 14/2, 2011 at 18:22 Comment(2)
Not an answer to your question, but you know there's two existing contact forms on the Gallery, and one of them is open source on CodePlex (shameless plug, I wrote it) contactform.codeplex.comIncrease
Paul, I actually tried your Module and logged two separate issues on CodePlex for it :)Lyudmila
L
14

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.

Lyudmila answered 15/2, 2011 at 18:57 Comment(1)
That's correct - classes mapped to record must be in /Records or /Models folder by convention.Caber
P
3

I got the same error from not having virtual variables in my record. (In my case it did not inherit ContentPartRecord and declared its 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.

Petepetechia answered 27/6, 2014 at 7:48 Comment(0)
W
0

My Favicon module has pretty much the same structure and when I did a file by file comparison I could not find a significant difference. The only thing that looks suspicious is that you didn't define a prefix in your driver. That may interfere with the binder's ability to rehydrate the model but I'm not sure how that would affect persistence.

Worldling answered 14/2, 2011 at 23:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.