Data Annotations实现概念模型和存储模型之间的映射

    //文章
    [Table("ArticleTB")]
    public class ArticleTB : BaseModelWithName
    {
        [Key]
        public int ID { get; set; }
        public ArticleTB()
            : base()
        {
        }

        public string Content { get; set; }
        public int CompanyID { get; set; }
        public int UserID { get; set; }
        [NotMapped]
        public UserTB UserTB { get; set; }
    }
模型类

完整的Data Annotations包括:(详细见 https://msdn.microsoft.com/en-us/library/jj193542(v=vs.113).aspx 第6部分) 
KeyAttribute 
StringLengthAttribute 
MaxLengthAttribute 
ConcurrencyCheckAttribute 
RequiredAttribute 
TimestampAttribute 
ComplexTypeAttribute 
ColumnAttribute 
TableAttribute 
InversePropertyAttribute 
ForeignKeyAttribute 
DatabaseGeneratedAttribute 
NotMappedAttribute

原文地址:https://www.cnblogs.com/liandy0906/p/8471640.html