配置模型

有两种方式配置与数据库之间的关系模型:fluent API 配置模型 和 数据注释模型

一、创建实体模型

1.创建实体模型

    [Table("T_BD_Sc")]
    public class Sc
    {
        [Key]
        public int SC_ID { get; set; }

        public string CODE { get; set; }

        public string NAME { get; set; }
    }

T_BD_Sc 是数据库真实的表名

如果不需要映射

    [NotMapped]
    public class Scale
    {
    }

二、属性

1.改变列名

        [Column("code1")]
        public string CODE { get; set; }

2.约定

(1)必填属性

        [Required]
        public string CODE { get; set; }

3.键

(1)主键

按照约定,将名为 Id 或 <type name>Id 的属性配置为实体的主键

public string Id { get; set; }
//或者
public string TruckId { get; set; }

或者

        [Key]
        public int SCALE_ID { get; set; }

(2)外键

原文地址:https://www.cnblogs.com/buchizaodian/p/13141314.html