Last active
August 8, 2021 19:08
-
-
Save marcfabregatb/580ae045cffbf847405874c9bf42c640 to your computer and use it in GitHub Desktop.
Entity Framework core 5 - Many to Many Relationship
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Category | |
{ | |
[Key] | |
[Column(TypeName = "VARCHAR")] | |
[StringLength(100)] | |
public string Name { get; set; } | |
public ICollection<BlogEntry> BlogEntries { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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