Orchard 项目模块出现错误:没有持久化:SomePartRecord
我正在尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的记录中没有有
虚拟
变量,也得到了同样的错误。(在我的例子中,它没有继承
ContentPartRecord
并声明了自己的Id
,不确定问题是否仅仅是Id
不是virtual
或者所有变量都必须是virtual
。)同样如上所述,您的命名空间必须以
Models
或Records
结尾,正如这里所解释的: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 ownId
, not sure if the issue simply was thatId
was notvirtual
or that all variables had to bevirtual
.)Also as mentioned above, your namespace must end with
Models
orRecords
, as explained here:https://orchard.codeplex.com/discussions/267968.
我的 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.
事实证明,如果您的零件和记录不在您的“模型”命名空间中,则这在果园中不起作用。当我更改两个类的命名空间时,它起作用了。一定是 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.