我正在尝试在Orchard中创建一个出现在设置页面中的简单设置.我创建了一个模块,它将我的ContentPart添加到设置页面并正确地在数据库中创建一个表,但每次呈现cshtml文件并访问记录的属性时,我都会获得以下NHibernate记录.
没有持久性:TekFlow.Contact.TekFlowEmailSettingsPartRecord.
(TekFlow.Contact是模块名称)
下面是我用于创建Orchard中所需的Record / Part / Handler / Driver的所有代码.
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("SomeEmail@somedomain.com").WithLength(255)) ); ContentDefinitionManager.AlterPartDefinition( typeof(TekFlowEmailSettingsPart).Name,cfg => cfg.Attachable()); return 1; } }
解决方法
事实证明,如果您的Part和Record不在您的“Models”命名空间中,那么它将无法在果园中运行.当我更改两个类的命名空间时,它工作.必须是Orchard正在做的假设.