Trouble Persisting non-content part data

Topics: Writing modules
Oct 7, 2011 at 7:40 AM

Hi, I'm getting a 'no persistor error' when trying to save my data. Any ideas?

I'm, actually integrating dhtmlx scheduler and it's close.  

namespace geoEvents {
    public class Migrations : DataMigrationImpl {

        public int Create() {
			SchemaBuilder.CreateTable("CalendarRecord", table => table
                .Column<int>("Id", column => column.PrimaryKey().Identity())
                .Column("text", DbType.String)
				.Column("start_date", DbType.DateTime)
                .Column("end_date", DbType.DateTime)
                .Column("rec_type", DbType.String)
                .Column("event_length", DbType.Int32)
                .Column("event_pid", DbType.Int32 )
);

The model used to be under models but in desperation tried under Records with same result..
namespace geoEvents.Records
{
    public class CalendarRecord 
    {
        public int Id { get; set; }
        [Required]
        public virtual string text { get; set; }
        [Required]
        public virtual DateTime? start_date { get; set; }
        [Required]
        public virtual DateTime? end_date { get; set; }
        public virtual Int32 event_pid { get; set; }
        public virtual Int32 event_length { get; set; }
        public virtual String rec_type { get; set; }
    }
}

Then I'm trying an insert in a controller..

namespace geoEvents.Controllers
{
    /// <summary>
    /// An ordinary ASP.NET MVC controller.
    /// You can create controllers and actions as in ordinary MVC applications.
    /// </summary>
    /// 

    public class CalendarController : Controller
    {


        private readonly IContentManager _contentManager;
        private readonly IContentDefinitionManager _contentDefinitionManager;
        private readonly ITransactionManager _transactionManager;
        private readonly ISiteService _siteService;

        private readonly IRepository<CalendarRecord> _repository;

        public IOrchardServices Services { get; set; }
        
        private readonly IOrchardServices _services;

        /// <summary>
        /// You can specify parameters in controller's ctor.
        /// Parameters will be injected by IoC controller with an appropriate object.
        /// IOrchardServices is the most commonly used object 
        /// - it is used to interact (get/save data from db, get request data and so on) with Orchard.
        /// </summary>
        /// <param name="services"></param>
        public CalendarController(IOrchardServices services, IRepository<CalendarRecord> repository, IContentManager contentmanager)
        {
            _services = services;
            _repository = repository;
            _contentManager = contentmanager;

        }

        public ActionResult Save(FormCollection actionValues)
        {
            String action_type = actionValues["!nativeeditor_status"];
            Int64 source_id = Int64.Parse(actionValues["id"]);
            Int64 target_id = source_id;
            CalendarRecord MyEvent = new CalendarRecord();

            try
            {
                switch (action_type)
                {
                    case "inserted":
                        
                        MyEvent.text = actionValues["text"];
                        MyEvent.start_date = DateTime.Parse(actionValues["start_date"]);
                        MyEvent.end_date = DateTime.Parse(actionValues["end_date"]);
                        MyEvent.rec_type = actionValues["rec_type"];
                        if (MyEvent.rec_type.Length > 0)
                        {
                            MyEvent.event_length = actionValues["event_length"].Length > 0 ? Convert.ToInt32(actionValues["event_length"]) : 0;
                            MyEvent.event_pid = actionValues["event_pid"].Length > 0 ? Convert.ToInt32(actionValues["event_pid"]) : 0;
                        }
                        _repository.Create(MyEvent );


Error is: No persister for: geoEvents.Records.CalendarRecord

Coordinator
Oct 7, 2011 at 7:42 PM

No handler?

Oct 10, 2011 at 2:25 AM

No, no handler. I thought they were for part data only. How would it look?

Oct 10, 2011 at 4:53 AM

Fixed it. Two days of futzing around and the issue was as simple as not declaring the Id as 'virtual'. Doh!

Feb 14, 2014 at 10:11 PM
Yeah, you don't need a handler for non-part records. But thanks, geodiction, for posting the solution as I probably wouldn't have found it easily.

For the record and everyone else out there struggling with this error, here we go:
  1. Record classes must be located in a namespace that ends with either .Models or .Records (see \src\Orchard\Environment\ShellBuilders\CompositionStrategy.cs -> IsRecord(Type type)).
  2. All members in Record classes must be virtual, especially the Id field.