hello,
I'm trying to bind scheduler to MS SQL database using EntityFramework 6 and Code First approach. I did it partly but I have a big problem with saving exceptions of recurring appointment.
First of all, I can't find any sample of such (it would seem) common scenario where recurring appointment's exceptional occurrences are stored in database using EntityFramework 6. I would be very grateful if someone could show me such an example because Telerik documentation sample doesn't work.
I have very simple code where I configure RadScheduler, SchedulerBindingDataSource and mapping between entities and scheduler fields. I'm pretty sure my Code First entity model and database tables and relations are correct. Despite this, I'm not able to store in database exceptions of recurring appointments. Recurring appointments with removed occurrences are properly stored and removed dates are saved in recurrence rule of appointment. But occurrences with exceptional time or duration are not saved at all.
Please, help me.
This is my appointment entity with self reference for exceptions:
01.[Table("App")]02.public class App03.{04. public App()05. {06. this.Resources = new HashSet<Res>();07. this.Exceptions = new HashSet<App>();08. }09. 10. [Key]11. [DatabaseGenerated(DatabaseGeneratedOption.None)]12. public Guid Id { get; set; }13. 14. [Required(AllowEmptyStrings = false)]15. [StringLength(255)]16. public string Summary { get; set; }17. 18. public DateTime Start { get; set; }19. 20. public DateTime End { get; set; }21. 22. public string RecurrenceRule { get; set; }23. 24. public bool Visible { get; set; }25. 26. [ForeignKey("MasterEvent")]27. public Guid? MasterEventID { get; set; }28. 29. 30. public virtual App MasterEvent { get; set; }31. 32. public virtual ICollection<App> Exceptions { get; set; }33. 34. public virtual ICollection<Res> Resources { get; set; }35.}
and my configuration of relations:
01.protected override void OnModelCreating(DbModelBuilder modelBuilder)02.{03. base.OnModelCreating(modelBuilder);04. 05. modelBuilder.Entity<App>()06. .HasMany(t => t.Resources)07. .WithMany(t => t.Apps)08. .Map(m => {09. m.ToTable("AppRes");10. m.MapLeftKey("AppId");11. m.MapRightKey("ResId");12. });13. 14. modelBuilder.Entity<App>()15. .HasOptional(t => t.MasterEvent)16. .WithMany(t => t.Exceptions)17. .HasForeignKey(t => t.MasterEventID)18. .WillCascadeOnDelete(true);19.}
and mapping:
01.var appointmentMappingInfo = new AppointmentMappingInfo()02.{03. UniqueId = "Id",04. Start = "Start",05. End = "End",06. Summary = "Summary",07. RecurrenceRule = "RecurrenceRule",08. Exceptions = "Exceptions",09. MasterEventId = "MasterEventID",10. Resources = "Resources",11. ResourceId = "Id",12. Visible = "Visible"13.};