开发者

Orchard Project Module getting error: No persister for: SomePartRecord

开发者 https://www.devze.com 2023-02-10 16:04 出处:网络
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

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("TekFlowEmail开发者_开发百科SettingsPartRecord",
             table => table
                 .ContentPartRecord()
                 .Column<string>("SendToEmail", c => c.WithDefault("SomeEmail@somedomain.com").WithLength(255))
             );


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

         return 1;
     }
 }


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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消