using System;using System.Collections.Generic;using System.Data.Entity.ModelConfiguration;using System.Linq;using System.Text;using System.Threading.Tasks;namespace firstCodeFirstApp{public class DonatorMap : EntityTypeConfiguration<Donator>{public DonatorMap(){ToTable("Donators");Property(m => m.Name).IsRequired();HasMany(d => d.PayWays).WithRequired().HasForeignKey(p => p.DonatorId);}}public class DonatorTypeMap : EntityTypeConfiguration<DonatorType>{public DonatorTypeMap(){HasMany(d => d.Donators).WithOptional(d => d.DonatorType) //外键约束可以为空.HasForeignKey(d => d.DonatorTypeId).WillCascadeOnDelete(false);}}public class StudentMap : EntityTypeConfiguration<Student>{public StudentMap(){HasRequired(s => s.Person).WithOptional(p => p.Student); // Optional 可选的HasKey(s => s.PersonId); //使用 HasKey 方法 指定一个表的主键Property(s => s.CollegeName).HasMaxLength(50).IsRequired();}}public class PersonMap : EntityTypeConfiguration<Person>{public PersonMap(){/** * MapLeftKey 配置左外键的列名。左外键指向在 HasMany 调用中指定的导航属性的父实体。* MapRightKey 配置右外键的列名。右外键指向在 WithMany 调用中指定的导航属性的父实体。*/HasMany(p => p.Companies).WithMany(c => c.Persons).Map(m => {m.MapLeftKey("PersonId");m.MapRightKey("CompanyId");});}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。