EntityTypeConfiguration
来源:互联网 发布:卖家怎么加入爱淘宝 编辑:程序博客网 时间:2024/06/06 19:02
我们配置的实体都都在OnModelCreating方法中,如果有很多实体的话,OnModelCreating方法管理很麻烦
我们可以用单独的类来管理配置,继承EntityTypeConfiguration<TEntity>类实现
public class StudentEntityConfiguration: EntityTypeConfiguration<Student>{ public StudentEntityConfiguration() { this.ToTable("StudentInfo"); this.HasKey<int>(s => s.StudentKey); this.Property(p => p.DateOfBirth) .HasColumnName("DoB") .HasColumnOrder(3) .HasColumnType("datetime2"); this.Property(p => p.StudentName) .HasMaxLength(50); this.Property(p => p.StudentName) .IsConcurrencyToken(); this.HasMany<Course>(s => s.Courses) .WithMany(c => c.Students) .Map(cs => { cs.MapLeftKey("StudentId"); cs.MapRightKey("CourseId"); cs.ToTable("StudentCourse"); }); }}
public class SchoolDBContext: DbContext { public SchoolDBContext(): base() { } public DbSet<Student> Students { get; set; } public DbSet<Standard> Standards { get; set; } public DbSet<StudentAddress> StudentAddress { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { // Moved all Student related configuration to StudentEntityConfiguration class modelBuilder.Configurations.Add(new StudentEntityConfiguration()); }}
阅读全文
0 0
- EntityTypeConfiguration
- EF Mapping3 EntityTypeConfiguration Class in Code-First
- EF使用EntityTypeConfiguration配置映射关系
- EF使用EntityTypeConfiguration配置映射关系
- Repository模式--采用EF Fluent API使用EntityTypeConfiguration分文件配置Model映射关系
- Repository模式--采用EF Fluent API使用EntityTypeConfiguration分文件配置Model映射关系
- Repository模式--采用EF Fluent API使用EntityTypeConfiguration分文件配置Model映射关系
- 可折叠TextView控件使用:ExpandableTextView
- combogrid实现分页、动态搜索、过滤手动输入
- textarea字数限制
- 使用datatables按自定义条件筛选数据
- NoSQL简介
- EntityTypeConfiguration
- Deli Deli(简单的STL + 字符串)
- springboot 启动错误 出现Caused by: java.lang.ClassNotFoundException: ch.qos.logback.classic.Level
- 【Python】提取网页正文内容的相关模块与技术
- 格式化输出只有固定小数点后位数
- make隐含规则
- 微信公众号开发(Java) ---- 模板消息接口的使用
- BZOJ 1202: [HNOI2005]狡猾的商人 并查集
- oracle用户默认表空间