一个官翻教程集合:ASP.NET Core 和 EF Core 系列教程

经过一个大学课程案例讲解了复杂实体的建立过程及讲解数据库

1.ASP.NET Core 和 Entity Framework Core 系列教程——入门 (1 / 10)mvc

2.ASP.NET Core 和 EF Core系列教程——CRUD (2 / 10)spa

3.ASP.NET Core 和 EF Core 系列教程——排序、筛选、分页和分组.net

4.ASP.NET Core 和 EF Core 系列教程——迁移翻译

基于core 2.0,做者只翻译了四篇,剩下的要去官网看机翻的了。code

官网地址:https://docs.microsoft.com/zh-cn/aspnet/core/data/ef-mvc/complex-data-model?view=aspnetcore-2.0blog

 

 

 

Student实体讲解
using System; using System.Collections.Generic; namespace ContosoUniversity.Models { public class Student { public int ID { get; set; } public string LastName { get; set; } public string FirstMidName { get; set; } public DateTime EnrollmentDate { get; set; } public ICollection<Enrollment> Enrollments { get; set; } } }

ID属性将成为对应于此类的数据库表中的主键。 默认状况下,EF 将会将名为ID或classnameID的属性解析为主键。排序

Enrollments属性是导航属性。 导航属性中包含与此实体相关的其余实体。 在这个案例下,Student entity中的Enrollments属性会保留全部与Student实体相关的Enrollment。 换而言之,若是在数据库中有两行描述同一个学生的修读状况 (两行的 StudentID 值相同,并且 StudentID 做为外键和某位学生的主键值相同),Student实体的Enrollments导航属性将包含那两个Enrollment实体。教程

若是导航属性能够具备多个实体 (如多对多或一对多关系),那么导航属性的类型必须是能够添加、 删除和更新条目的容器,如ICollection<T>。 你能够指定ICollection<T>或实现该接口类型,如List<T>或HashSet<T>。 若是指定ICollection<T>,EF在默认状况下建立HashSet<T>集合。接口

相关文章
相关标签/搜索