В моем модуле сада все работает нормально, но, к сожалению, база данных не обновляется.Orchard CMS - Handler не обновляет базу данных
Я определил вид на панели администратора на Orchard.Web \ Modules \ курс \ Views \ EditorTemplates \ частей \ Course.cshtml, как показано ниже:
@model Course.Models.CoursePart
<fieldset>
<legend>Course Fields</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Title)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.Title)
@Html.ValidationMessageFor(model => model.Title)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Description)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ImagePath)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.ImagePath)
@Html.ValidationMessageFor(model => model.ImagePath)
</div>
</fieldset>
и водитель, как показано ниже:
public class CourseDriver : ContentPartDriver<CoursePart>
{
protected override DriverResult Display(CoursePart part,
string displayType,
dynamic shapeHelper)
{
return ContentShape("Parts_Course",
() => shapeHelper.Parts_Course(
Description: part.Description,
Title: part.Title,
ImagePath: part.ImagePath,
Area: part.Area
));
}
//GET
protected override DriverResult Editor(CoursePart part,
dynamic shapeHelper)
{
return ContentShape("Parts_Course_Edit",
() => shapeHelper.EditorTemplate(
TemplateName: "Parts/Course",
Model: part,
Prefix: Prefix));
}
//POST
protected override DriverResult Editor(CoursePart part,
IUpdateModel updater,
dynamic shapeHelper)
{
updater.TryUpdateModel(part, Prefix, null, null);
return Editor(part, shapeHelper);
}
}
И Handler:
namespace Course.Handlers
{
public class CourseHandler: ContentHandler
{
public CourseHandler(IRepository<CourseRecord> repository)
{
Filters.Add(StorageFilter.For(repository));
}
}
}
класс миграции, описанный ниже, находится в файле Orchard.Web \ Modules \ Course \ Migrations.cs.
namespace Course {
public class Migrations : DataMigrationImpl {
public int Create() {
// Creating table CoursePartRecord
SchemaBuilder.CreateTable("CourseRecord", table => table
.ContentPartRecord()
.Column("Area", DbType.String)
.Column("Description", DbType.String)
.Column("Title", DbType.String)
.Column("ImagePath", DbType.String)
);
//Add the AlterPartDefinition lines to the migration in order to make the part
//attachable to any content type.
ContentDefinitionManager.AlterPartDefinition(
typeof(CoursePart).Name, cfg => cfg.Attachable());
return 1;
}
public int UpdateFrom1()
{
ContentDefinitionManager.AlterTypeDefinition("CourseContent", cfg => cfg
.WithPart("CommonPart")
.WithPart("RoutePart")
.WithPart("BodyPart")
.WithPart("CoursePart")
.WithPart("CommentsPart")
.WithPart("TagsPart")
.WithPart("LocalizationPart")
.Creatable()
.Indexed());
return 2;
}
}
}
Модель описана ниже:
namespace Course.Models
{
public class CourseRecord : ContentPartRecord
{
public virtual String Area { get; set; }
public virtual String Description { get; set; }
public virtual String Title { get; set; }
public virtual String ImagePath { get; set; }
}
public class CoursePart : ContentPart<CourseRecord>
{
public String Area { get; set; }
[Required]
public String Description { get; set; }
[Required]
public String Title { get; set; }
public String ImagePath { get; set; }
}
}
Я следовал шагам в соответствии с примером, в документации фруктового сада: http://docs.orchardproject.net/Documentation/Writing-a-content-part.
Проблема: база данных не создается и обновляется, каждое свойство из записи обновляется с нулевыми значениями, то repository.Table
в CourseHandler
метод всегда возвращает список.
С наилучшими пожеланиями, Тито
Можете ли вы показать нам свой класс миграциями и ваш класс CourseRecord? – mdm
@mdm, теперь я уже добавил. Спасибо, что заметил это. – Tito