Answer the question
In order to leave comments, you need to log in
Entity Framework Code First - why when creating a one to many relationship, 2 columns are created in the table?
I use Entity Framework Code First technology when designing a database for my blog.
At the moment, I am writing the essence of the article (Article) and comments (Comment).
The Article entity refers to Comment - one to many.
Why, when creating a database, the framework creates 2 columns in the Comment table at once:
Comment_ID (why?)
Article_ID (everything is clear with this one).
Moreover, in the Comment_ID column, all NULL values
Answer the question
In order to leave comments, you need to log in
Show some code? I think I wrote something wrong
public class Article
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
...
public virtual ICollection<Comment> comm { get; set; }
}
public class Comment
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
public Guid ArtId { get; set; }
...
[ForeignKey("ArtId")]
public virtual Article art { get; set; }
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question