Orchard 项目模块出现错误:没有持久化:SomePartRecord

发布于 2024-10-17 06:32:28 字数 2479 浏览 1 评论 0原文

我正在尝试在 Orchard 中创建一个出现在设置页面中的简单设置。我创建了一个模块,它将我的 ContentPart 添加到设置页面,并在数据库中正确创建一个表,但每次渲染 cshtml 文件并访问记录的属性时,我都会不断收到以下 NHibernate 记录。

没有持久化:TekFlow.Contact.TekFlowEmailSettingsPartRecord。 (TekFlow.Contact 是模块名称)

下面是我用来创建 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;
     }
 }

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;
     }
 }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

恏ㄋ傷疤忘ㄋ疼 2024-10-24 06:32:29

我的记录中没有虚拟变量,也得到了同样的错误。
(在我的例子中,它没有继承 ContentPartRecord 并声明了自己的 Id,不确定问题是否仅仅是 Id 不是 virtual 或者所有变量都必须是virtual。)

同样如上所述,您的命名空间必须以 ModelsRecords 结尾,正如这里所解释的:
https://orchard.codeplex.com/discussions/267968

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.

无需解释 2024-10-24 06:32:29

我的 Favicon 模块具有几乎相同的结构,当我逐个文件比较时,我找不到显着的差异。唯一看起来可疑的是您没有在驱动程序中定义前缀。这可能会干扰粘合剂重新水合模型的能力,但我不确定这会如何影响持久性。

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.

何处潇湘 2024-10-24 06:32:28

事实证明,如果您的零件和记录不在您的“模型”命名空间中,则这在果园中不起作用。当我更改两个类的命名空间时,它起作用了。一定是 Orchard 做出的假设。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文