This is a migrated thread and some comments may be shown as answers.

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

5 Answers 146 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Colin
Top achievements
Rank 2
Colin asked on 16 Jun 2014, 11:08 AM
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.

5 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 17 Jun 2014, 01:12 PM
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.
 
0
Colin
Top achievements
Rank 2
answered on 17 Jun 2014, 03:00 PM
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

0
Colin
Top achievements
Rank 2
answered on 19 Jun 2014, 08:58 AM
It took me a while to find out what is going on, but finally I've got the database created.
0
Colin
Top achievements
Rank 2
answered on 19 Jun 2014, 08:59 AM
Thank you :)
0
Yana
Telerik team
answered on 20 Jun 2014, 08:54 AM
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.
 
Tags
ScheduleView
Asked by
Colin
Top achievements
Rank 2
Answers by
Yana
Telerik team
Colin
Top achievements
Rank 2
Share this question
or