EF Core NotMapped、Column、Comment

一、NotMapped

模型中的每个实体类型都具有一组属性,这些属性 EF Core 将从数据库中读取和写入数据。 如果使用关系数据库,实体属性将映射到数据库表列。但当某个属性只用于展示,不需要映射到数据库,就需要使用 [NotMapped]属性

	[Table("QcwGoodss")]
    public class Goods : AuditedEntity<Guid>
    {
        /// <summary>
        /// 货品名称
        /// </summary>
        public string GoodsName { get; set; }
        /// <summary>
        /// 货品类型
        /// </summary>
        public string GoodsType { get; set; }
        /// <summary>
        /// 存放位置
        /// </summary>
        public string Location { get; set; }
        /// <summary>
        /// 货品数量
        /// </summary>
        public int GoodsNum { get; set; }

        /// <summary>
        ///  用于显示
        /// </summary>
        [NotMapped]
        public string GoodsCode { get { return GoodsName.Substring(0, 1) + ":" + Location; } }

        public virtual Guid InboundRecordId { get; set; }
        [ForeignKey(nameof(InboundRecordId))]
        public virtual InboundRecord InboundRecord { get; set; }
    }

二、Column

更改数据库字段名和字段的数据类型

		/// <summary>
        /// 货品类型
        /// </summary>
        [Column(TypeName = "varchar(200)")]
        [Column("GoodsTypeTest")]
        [StringLength(MaxCodeLength)]
        public string GoodsType { get; set; }

三、Comment

在数据库列上设置的任意文本注释,以允许您在数据库中记录架构

 		/// <summary>
        /// 存放位置
        /// </summary>
        [Comment("The URL of the blog")]
        [StringLength(MaxRemarkLength)]
        public string Location { get; set; }

在这里插入图片描述