1.数据库上线文

    [DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
    class MyContext : DbContext
    {
        public MyContext():base("name=MyContext")
        {
        }
        public virtual DbSet<DataType> DataTypes { get; set; }
    }
2.简单默认

    //数据类型
    public class DataType
    {
        [Key]
        public int ID { get; set; }     // int(11)  primary key

        public string Name { get; set; } //LONGTEXT

        public virtual List<DataType2> DataType2s { get; set; }
    }
3.基本类型

    //常用数据类型 ,外键
    public class DataType2
    {
        [Key]
        public int ID { get; set; }
        [MaxLength(200)]
        public string Title { get; set; } //varchar(200)

        public DateTime Birthday { get; set; } //DateTime


        public bool IsDelete { get; set; } //tinyint(1)

        public int ParentID { get; set; }

        public double Number1 { get; set; } //double

        public float Number2 { get; set; } //float


        [ForeignKey("ParentID")]                       //外键属性
        public virtual DataType DataType { get; set; } //On Update:Cascade 
                                                       //On Delete:Cascade

        public virtual List<DataType3> DataType3s { get; set; }
    }

4.可空类型

    //可空类型 
    public class DataType3
    {
        [Key]
        public int ID { get; set; }


        public int? Number { get; set; }    //int(11) 可空
        public bool? IsDelete { get; set; } //tinyint(1) 可空
        public DateTime? Birhday { get; set; } //datetime 可空


        public double? Number1 { get; set; }  //double 可空
        public float? Number2 { get; set; }   //float 可空

        public int? ParentID { get; set; }


        [ForeignKey("ParentID")]                        //外键属性
        public virtual DataType2 DataType2 { get; set; }//On Update:Restrict
                                               //On Delete:Restrict
    }                                                 


本文转载:CSDN博客