I am getting this error on the following code
The supplied instance is not of type Telerik.OpenAccess.SPI.dataobjects.PersistenceCapable (ShopMaintenance.Scheduled+Task). Are you trying to add a wrong object or is the assembly not enhanced?
//Find all "Daily" tasks from the TaskPool table and populate the calendar with them
public static void Daily_Tasks(){
ShopMaintenanceEntityDiagrams context = new ShopMaintenanceEntityDiagrams();
IQueryable<TaskPool> query = from c in context.TaskPools
where c.Cycle == "Daily"
select c;
foreach (TaskPool taskpool in query)
{
int months = 12;
int days = DateTime.DaysInMonth(DateTime.Now.Year, months);
while (months > 0)
{
while (days > 0)
{
DateTime daily = new DateTime(DateTime.Now.Year, months, days, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
switch (daily.DayOfWeek)
{
case DayOfWeek.Saturday:
break;
case DayOfWeek.Sunday:
break;
default:
Calendar.Appointments.Add(new Calendar(taskpool.ID, taskpool.Name, taskpool.Notes, daily, daily.AddHours(1)));
Task task = new Task();
task.Id =
Guid.NewGuid().ToString();
task.TaskName = taskpool.Name;
task.TaskNotes = taskpool.Notes;
task.Start = daily;
task.End = daily.AddHours(1);
context.Add(task);
context.SaveChanges();
break;
}
days--;
}
if (months >= 1)
{
months--;
if (months != 0)
{
days =
DateTime.DaysInMonth(DateTime.Now.Year, months);
}
}
}
}
Any thoughts? Thanks!
Eric