This project is read-only.

Why can't save sucessful

Topics: Core, General
Dec 3, 2012 at 10:17 AM

I encountered a problem: I have define the field "ProjectSponsor" in PartRecord and Part, and add the column to the DB thru migaration file. And in the cshtml:

...@Html.LabelFor(m => m.ProjectSponsor, T("Project Sponsor: "))
<select id="@Html.FieldIdFor(m => m.ProjectSponsor)" name="@Html.FieldNameFor(m => m.ProjectSponsor)">
        @Html.SelectOption(Model.ProjectSponsor, "1", T("Lorry").Text);
        @Html.SelectOption(Model.ProjectSponsor, "2", T("Floyd").Text);
        @Html.SelectOption(Model.ProjectSponsor, "3", T("Jeff Jin").Text);

And I debug in the EditPost method:

dynamic model = _services.ContentManager.UpdateEditor(contentItem, this);



When I run after the "dynamic model = _services.ContentManager.UpdateEditor(contentItem, this);", I thru the quick watch windows I found the "model" has get the "ProjectSponsor" value, but in the end it save failed, I mean no exception throwed, but in the table of Database, the value still be null.

I have cost some time on it, but no idear, how do you think about it?

Dec 3, 2012 at 1:15 PM

And then I delete the table, re-create table still can't insert/modify successful, at last I try to drop the Database, re-create the DB, it can work well, it must the relationship between part field and Table field can't be reflection, but what I need to do it? Or something other where I did wrong?

Dec 3, 2012 at 8:07 PM

There has to be an exception. Attach a debugger and step through the code.

Dec 4, 2012 at 1:11 AM

I don't enable the "Migaration" model, I don't know if it cause the problem? Or if there exists other module I need to enable to make sure change will be used for migaration?

Dec 4, 2012 at 2:00 AM

I'm sorry, I don't understand what you mean.

Dec 4, 2012 at 5:50 AM

I mean in the admin page, I click the "Modules" link and navigate to the Module List page, I found the feature of "Migaration" and "Database Update" isn't enabled, so I think save failure may be for the feature isn't enabled. Am I right? 

Dec 4, 2012 at 7:54 AM

No those are unrelated to your problem and don't need to be enabled. They are for the command line only.

Dec 4, 2012 at 9:55 AM

bertrandleroy, thank you for reply. I have another problem want to ask you: I want to record user operation(to log operation to DB), I define a record entity:

public class StatusChangeHistoryRecord {
        public virtual int ItemID { get; set; }
        public virtual string CSType { get; set; }
        public virtual int SubmitterID { get; set; }


On the migration file I create the table, and it create table succefully.  Then I create a service:

private readonly IRepository<StatusChangeHistoryRecord> _logRepository; (I get it in the service constructor)

public void AddHistoryRecord(int pContentItemID, CSType pCSType, DateTime pChangeDate, int? pOldStatus, int pCurrentStatus, ContentItem pItem) {
            StatusChangeHistoryRecord record = new StatusChangeHistoryRecord();
            record.ItemID = pContentItemID;
            record.CSType = pCSType.ToString();

after run, I got the exception "No persister for: Levis.Leaves.Core.Models.StatusChangeHistoryRecord", I know it means the model don't mappting to the table in the DB, what I should do?

Dec 4, 2012 at 10:14 AM

And I can't in the handler used Filters.Add(StorageFilter.For(repository)), because the record don't inherit the ContentPartRecord.

Dec 5, 2012 at 1:27 AM

I have find the reason: If a record don't inherit the ContentPartRecord, it must declare a property "Id", only do that, it will be mapped to table in the DB.