zoukankan      html  css  js  c++  java
  • Configuring a Composite primary key or Foreign Key 复合主键外键的写法

    If the primary key on the Department type consisted of DepartmentID and Name properties, you would configure the primary key for the Department and the foreign key on the Course types as follows:
    如果 Department 类型的主键由 DepartmentID 和 Name 属性组成,那么您将配置 Department 的主键和 Course 类型的外键,如下所示:

    // Composite primary key 
    modelBuilder.Entity<Department>() 
    .HasKey(d => new { d.DepartmentID, d.Name }); 
     
    // Composite foreign key 
    modelBuilder.Entity<Course>()  
        .HasRequired(c => c.Department)  
        .WithMany(d => d.Courses) 
        .HasForeignKey(d => new { d.DepartmentID, d.DepartmentName });
     
    参考:http://msdn.microsoft.com/en-us/data/jj591620.aspx

    来自:https://blog.csdn.net/hejisan/article/details/35783235

  • 相关阅读:
    分割线
    PTA 乙级 1053 住房空置率 (20分) C/C++
    5.12 记录
    单词统计
    eclipse导入项目jdk版本不一样
    5.6日 项目回顾
    5.5 记录
    5.3 记录
    5.2 记录
    5.1 记录
  • 原文地址:https://www.cnblogs.com/djd66/p/14849457.html
Copyright © 2011-2022 走看看