Create a database via Entity Framework 6 code first for Telerik RadscheduleView

6 posts, 0 answers
  1. Colin
    Colin avatar
    19 posts
    Member since:
    Jun 2011

    Posted 16 Jun 2014 Link to this post

    Hi,

    I am trying to use Telerik RadScheduleView, but I cannot
    find a decent example online how to implement the following interfaces, in
    order to get the entities for my database right

    -         IAppointment, IExtendedAppointment
    -         IResource
    -         IExceptionOccurrence,
    -         IResourceType
    -         ICategory
    -        ITimeMarker

    I also tried to implement the default Telerik classes for
    these, but when I try to create the database I get the following errors:

    TelerikBaseClasses.Brush: : EntityType 'Brush' has no key
    defined. Define the key for this EntityType.

    TelerikBaseClasses.Transform: : EntityType 'Transform' has
    no key defined. Define the key for this EntityType.

    TelerikBaseClasses.BitmapEffect: : EntityType 'BitmapEffect'
    has no key defined. Define the key for this EntityType.

    TelerikBaseClasses.BitmapEffectInput: : EntityType
    'BitmapEffectInput' has no key defined. Define the key for this EntityType.

    TelerikBaseClasses.Geometry: : EntityType 'Geometry' has no
    key defined. Define the key for this EntityType.

    TelerikBaseClasses.PathFigure: : EntityType 'PathFigure' has
    no key defined. Define the key for this EntityType.

    TelerikBaseClasses.PathSegment: : EntityType 'PathSegment'
    has no key defined. Define the key for this EntityType.

     

    There is many more of these errors and I have no idea what
    to do with them. I am using Entity Framework 6 code first.

    I would like to get an example that shows how to generate a
    database based on either those interfaces or classes.

  2. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 17 Jun 2014 Link to this post

    Hi Colin,

    I would suggest that you take a look at our ScheduleView Binding to Database tutorial and to the referenced example in our SDK Repository (https://github.com/telerik/xaml-sdk/tree/master/ScheduleView/Database/WPF_CS). Note that the demonstrated approach is for ADO.NET Entity Framework 4.1, however you could check how the needed interfaces are implemented there.

    I hope this will help get started.

    Regards,
    Yana
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Colin
    Colin avatar
    19 posts
    Member since:
    Jun 2011

    Posted 17 Jun 2014 in reply to Yana Link to this post

    Hi Yana,

    Thank you for your answer, I’ve had a look at suggested
    links yesterday, however I haven’t found a clear solution. There is too many
    missing puzzles, for example I created SqlAppointment class
    which looks like this:

    public class SqlAppointment : IAppointment, IExtendedAppointment
        {
            public int SqlAppointmentId { get; set; }
            public string Subject { get; set; }
            public string Body { get; set; }
            public DateTime Start { get; set; }
            public DateTime End { get; set; }
            public bool IsAllDayEvent { get; set; }
            public IRecurrenceRule RecurrenceRule { get; set; }
            public TimeZoneInfo TimeZone { get; set; }
            public Importance Importance { get; set; }
            public int? TimeMarkerId { get; set; }
            public int? CategoryId { get; set; }

            //keys
            public virtual TimeMarker TimeMarker2 { get; set; }
            public virtual Category Category2 { get; set; }

            //I am not sure what to do with these because I cant use them as navigation properties
            public ITimeMarker TimeMarker { get; set; }
            public ICategory Category { get; set; }

            public string RecurrencePattern { get; set; }

            public event EventHandler RecurrenceRuleChanged;

            private IList resources;
            public IList Resources
            {
                get
                {
                    if (resources == null)
                    {
                        resources = new ObservableCollection<SqlResource>();
                    }
                    return resources;
                }
            }

            public event PropertyChangedEventHandler PropertyChanged;

            public void BeginEdit()
            {
                //TODO:implement
                //throw new System.NotImplementedException();
            }

            public void CancelEdit()
            {
                //TODO:implement
                //throw new System.NotImplementedException();
            }

            public void EndEdit()
            {
                //TODO:implement
                //throw new System.NotImplementedException();
            }

            public bool Equals(IAppointment other)
            {
                throw new System.NotImplementedException();
            }

            public IAppointment Copy()
            {
                IAppointment appointment = new SqlAppointment();
                appointment.CopyFrom(this);
                return appointment;
            }

            public void CopyFrom(IAppointment other)
            {
                throw new System.NotImplementedException();
            }
        }

    When I implement the interfaces I get those two fields I mentioned
    in the comment above. However I can’t use property of type interface as
    navigation property in entity framework as far as I know. I also didn’t know
    how to handle TimeZoneInfo so
    for the moment in the configuration class I told the EF to ignore it (I probably
    want need it anyway).

    My configuration class for the SqlAppointment looks like
    this:

        public class SqlAppointmentConfiguration : EntityTypeConfiguration<SqlAppointment>
        {
            public SqlAppointmentConfiguration()
            {
                ToTable("SqlAppointment", "MAScheduleView");

                Property(p => p.Subject).HasMaxLength(100).IsOptional();
                Property(p => p.Body).HasMaxLength(500).IsOptional();
                Property(p => p.Start).HasColumnType("datetime2").IsRequired();
                Property(p => p.End).HasColumnType("datetime2").IsRequired();

                //not sure how to implement this pattern, but i worry about this later, when i have other things working
                Property(p => p.RecurrencePattern).HasMaxLength(100).IsOptional();

                HasOptional(p => p.TimeMarker2).WithMany().HasForeignKey(p => p.TimeMarkerId).WillCascadeOnDelete(false);
                HasOptional(p => p.Category2).WithMany().HasForeignKey(p => p.CategoryId).WillCascadeOnDelete(false);
      
               Ignore(p => p.TimeZone);
            }
        }

    I managed to get it run, and produce all the classes I found
    in the documentation, more or less correct. But I struggle to understand what
    class represents what, because the documentation is not very specific at
    places.

    I managed to hook up a quick wpf test up and I quickly find
    out that I was able to store an appointment together with the category id, but
    when I re-run the app the appointment is not aware of its category. I made
    another post about it http://www.telerik.com/forums/when-the-appointments-are-read-from-the-database-categories-for-each-one-does-not-show
    at this moment there is lots of questions that don’t seem to have any answer
    anywhere, this is the first time im trying to implement anything from Telerik
    so I really need some help please.

    Would anyone be so kind to have a look at my sample project
    if I posted it? To tell me what am I doing wrong?

     

    Kind regards

  5. Colin
    Colin avatar
    19 posts
    Member since:
    Jun 2011

    Posted 19 Jun 2014 in reply to Colin Link to this post

    It took me a while to find out what is going on, but finally I've got the database created.
  6. Colin
    Colin avatar
    19 posts
    Member since:
    Jun 2011

    Posted 19 Jun 2014 in reply to Colin Link to this post

    Thank you :)
  7. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 20 Jun 2014 Link to this post

    Hi Colin,

    I am glad to hear that you've managed to resolve the issue. And also thank you for sending your feedback, we will consider improving our documentation on the approach and adding some comments in code.

    Regards,
    Yana
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top
UI for WPF is Visual Studio 2017 Ready