0

Im creating a blog i try to "connect" a list of comments to each blog-posts:

public class BlogPost
    {
        public int BlogPostId { get; set; }
        public string Post { get; set; }
    }

comment-class:

public class Comment
    {
        public int CommentId { get; set; }
        public string Comment { get; set; }
    }

How do I specify in my BlogPost-class that I want it to be able to have a list of comments to it?

1 Answer 1

1

You need to configure a one-to-many relationship like:

public class BlogPost
{
    ...
    public virtual ICollection<Comment> Comments { get; set; }
}

and

public class Comment
{
    ...
    public virtual Comment Comment { get; set; }
}

You can have more informations on: http://www.entityframeworktutorial.net/code-first/configure-one-to-many-relationship-in-code-first.aspx

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.