а

Error due to model


#1

Hello all,

I am fairly new to ASP.net and MVC (5) so I have some trouble.

I wanted to add a calendar, with a custom lightbox. The custom lightbox involves recurring and choosing a “group”.
The recurring works well, but choosing a “group” has been bugging. It gives an error saying I have an invalid column named group.

My model:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

using DHTMLX.Scheduler;

namespace WebApplication1.Models
{
    public class Appointment
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [DHXJson(Alias = "id")]
        public int Id { get; set; }

        [DHXJson(Alias = "text")]
        public string Description { get; set; }

        [DHXJson(Alias = "start_date")]
        public DateTime StartDate { get; set; }

        [DHXJson(Alias = "end_date")]
        public DateTime EndDate { get; set; }

        [DHXJson(Alias = "event_length")]
        public long EventLength { get; set; }

        [DHXJson(Alias = "rec_type")]
        public string RecType { get; set; }

        [DHXJson(Alias = "event_pid")]
        public int EventPid { get; set; }

        [DHXJson(Alias = "Group")]
        public string Group { get; set; }
    }
}

Implementation in the controller:

public ActionResult Index()
        {
            var scheduler = new DHXScheduler(this);
            scheduler.Skin = DHXScheduler.Skins.Flat;

            scheduler.Config.first_hour = 6;
            scheduler.Config.last_hour = 20;
            
            scheduler.Lightbox.Add(new LightboxText("text", "Description"));
            scheduler.Lightbox.Add(new LightboxRecurringBlock("rec_pattern", "Recurring"));
            scheduler.Lightbox.Add(new LightboxMiniCalendar("time", "Time period"));
            
            var groupsSelect = new LightboxSelect("group", "group");
            
            var items = new List<object>(){
                new { key = "1", label = "HSE1" },
                new { key = "2", label = "HSE2" },
                new { key = "3", label = "HSE3" }
            };
            groupsSelect.AddOptions(items);
            groupsSelect.MapTo = "Group";

            scheduler.Lightbox.Add(groupsSelect);

            scheduler.EnableDynamicLoading(SchedulerDataLoader.DynamicalLoadingMode.Month);

            scheduler.LoadData = true;
            scheduler.EnableDataprocessor = true;

            scheduler.Extensions.Add(SchedulerExtensions.Extension.Recurring);
            return View(scheduler);
        }

The error arrises here:

public ContentResult Data(DateTime from, DateTime to)
        {
            var apps = db.Appointments.Where(Appointment => Appointment.StartDate < to && Appointment.EndDate >= from).ToList();
            return new SchedulerAjaxData(apps);
        }

at “var apps…” part to be more precise

The error is as followed:

System.Data.Entity.Core.EntityCommandExecutionException
  HResult=0x8013193C
  Message=An error occurred while executing the command definition. See the inner exception for details.
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>

Inner Exception 1:
SqlException: Invalid column name 'Group'.

How do I fix this error?

Thanks in advance