1
1
1ncomparable2017-11-21 00:55:21
ASP.NET
1ncomparable, 2017-11-21 00:55:21

Entity Framework Code First, database creation problem, what should I do?

I have classes:

public class Topic
    {
        public int Id { get; set; }

        public string Name { get; set; }

        public string Description { get; set; }

        public DateTime Time { get; set; }

        public List<Lesson> Lessons { get; set; }

        public List<string> Tags { get; set; }

        public Topic()
        {
            Lessons = new List<Lesson>();

            Tags = new List<string>();
        }
    }
public class Lesson
    {
        public int Id { get; set; }

        public int TopicId { get; set; }

        public Topic Topic { get; set; }

        public string Name { get; set; }

        public List<Paragraph> Paragraphs { get; set; }

        public List<LTask> Tasks { get; set; }

        public Lesson()
        {
            Paragraphs = new List<Paragraph>();

            Tasks = new List<LTask>();
        }
    }
public class LTask
    {
        public int Id { get; set; }

        public int LessonId { get; set; }

        public Lesson Lesson { get; set; }

        public string HeadLine { get; set; }

        public string Question { get; set; }

        public string Answer { get; set; }
    }
public class Paragraph
    {
        public int Id { get; set; }

        public int LessonId { get; set; }

        public Lesson Lesson { get; set; }

        public string HeadLine { get; set; }

        public string Text { get; set; }
    }

And also the context:
public class CourseContext : DbContext
    {
        public CourseContext()
            : base("name=CourseContext")
        {
        }

        public DbSet<Topic> Topics { get; set; }

        public DbSet<string> Tags { get; set; }

        public DbSet<Lesson> Lessons { get; set; }

        public DbSet<Paragraph> Paragraphs { get; set; }

        public DbSet<LTask> Tasks { get; set; }
    }

But when I run the application, I get an error: "Type 'System.String' has not been mapped. Verify that the type has not been explicitly excluded using the Ignore method or the NotMappedAttribute data annotation. Verify that the type is defined as a class, not a primitive type, or generic type, and also does not inherit from EntityObject."
Can you help with solving this problem? I tried to solve it myself, but I couldn't.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
Jan, 2017-11-21
@on1k

Make Tags as a class with Id, Tag fields and specify it in links

D
Duskone39, 2019-07-27
@Duskone39

It's just that you can't use standard data types in DbSet, only classes created by you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question