Fontagent 6 info7/6/2023 This match determines which blog every post is related to. This column is "constrained" such that any value in the BlogId column of Posts must match a value in the Id column of Blogs. The Blogs primary key column Id is referenced by the BlogId foreign key column of the Posts table. In addition, the Blogs table is given a "foreign key" column. The value of the primary key uniquely identifies each post or blog. In this relational model, the Posts and Blogs tables are each given a "primary key" column. For example, using SQL Server or Azure SQL, the following tables can be used to represent our Post and Blog classes: CREATE TABLE (ĬONSTRAINT PRIMARY KEY (),ĬONSTRAINT FOREIGN KEY () REFERENCES () ON DELETE CASCADE) ĬONSTRAINT PRIMARY KEY ()) Relational databases represent relationships using foreign keys. In EF Core, the Blog.Posts and Post.Blog properties are called "navigations". This connection from Blog to Post and, inversely, from Post back to Blog is known as a "relationship" in EF Core. Likewise, the opposite direction of the same relationship can be represented as a collection of Post objects on each Blog: public class Blog In an object-oriented language like C#, the blog and post are typically represented by two classes: Blog and Post. For example, when modeling posts in a blog, each post is related to the blog it is published on, and the blog is related to all the posts published on that blog. Relationships in object modelsĪ relationship defines how two entities relate to each other. This document provides a simple introduction to the representation of relationships in object models and relational databases, including how EF Core maps between the two.
0 Comments
Leave a Reply. |