- Mastering Entity Framework Core 2.0
- Prabhakaran Anbazhagan
- 249字
- 2021-07-02 21:16:37
Post entity
Create a Post.cs class file and include the following properties:
public class Post
{
public int Id { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public DateTime PublishedDateTime { get; set; }
public int BlogId { get; set; }
public Blog Blog { get; set; }
}
The BlogId property is a foreign key created for the corresponding Blog navigation property. As you may notice in this case, we have an inpidual item as the navigation property, as opposed to a list in the Blog entity. This is where relationship type comes into the picture, which we will be exploring more in Chapter 3, Relationships – Terminology and Conventions.
EF will allow us to create an inpidual navigation property without any foreign key in the entity. In those cases, EF will create a foreign key for us in the database table using the BlogId pattern (the Blog navigation property along with its Id primary key). EF will generate them automatically for all navigational properties against the Id primary key, but it also allows us to name it differently and decorate it via a custom attribute.
We have built the schema required for the application so far, but it was not configured in EF, so let's see how the data models get connected/configured with EF using database context.
- HornetQ Messaging Developer’s Guide
- Hands-On Machine Learning with scikit:learn and Scientific Python Toolkits
- 劍指JVM:虛擬機實踐與性能調優
- HTML5 移動Web開發從入門到精通(微課精編版)
- 區塊鏈:以太坊DApp開發實戰
- Python高效開發實戰:Django、Tornado、Flask、Twisted(第3版)
- C語言程序設計同步訓練與上機指導(第三版)
- Mastering JavaScript Design Patterns(Second Edition)
- Jenkins Continuous Integration Cookbook(Second Edition)
- PySide 6/PyQt 6快速開發與實戰
- Visual FoxPro程序設計習題集及實驗指導(第四版)
- R用戶Python學習指南:數據科學方法
- Learning Docker Networking
- C++程序設計教程(第2版)
- Flink入門與實戰