Skip to content

Instantly share code, notes, and snippets.

@marcfabregatb
Last active August 8, 2021 19:08
Show Gist options
  • Save marcfabregatb/580ae045cffbf847405874c9bf42c640 to your computer and use it in GitHub Desktop.
Save marcfabregatb/580ae045cffbf847405874c9bf42c640 to your computer and use it in GitHub Desktop.
Entity Framework core 5 - Many to Many Relationship
public class BlogEntry
{
[Key]
public string Id { get; set; }
[Required]
[MaxLength(200)]
public string Title { get; set; }
[Required]
public string Text { get; set; }
public ICollection<Category> Categories { get; set; }
}
public class Category
{
[Key]
[Column(TypeName = "VARCHAR")]
[StringLength(100)]
public string Name { get; set; }
public ICollection<BlogEntry> BlogEntries { get; set; }
}
public DbSet<BlogEntry> BlogEntries { get; set; }
public DbSet<Category> Categories { get; set; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment