EntityFramework CodeFirst自动生成代码(个人笔记)

数据表格式

EntityFramework CodeFirst自动生成代码(个人笔记)_第1张图片

SQL语句

CREATE TABLE [dbo].[Brand] (
    [Id]         UNIQUEIDENTIFIER NOT NULL,
    [Name]       NVARCHAR (50)    NOT NULL,
    [Initials]   NVARCHAR (50)    NOT NULL,
    [Tag]        NVARCHAR (50)    NULL,
    [Remark]     NVARCHAR (500)   NULL,
    [CreateDate] DATETIME         NULL,
    [LastDate]   DATETIME         NULL,
    CONSTRAINT [PK_dbo.Brand] PRIMARY KEY CLUSTERED ([Id] ASC)
);
CREATE TABLE [dbo].[ProductInfo] (
    [Id]             UNIQUEIDENTIFIER NOT NULL,
    [BrandId]        UNIQUEIDENTIFIER NULL,
    [CategoryId]     UNIQUEIDENTIFIER NULL,
    [Model]          NVARCHAR (50)    NOT NULL,
    [SN]             NVARCHAR (50)    NULL,
    [Version]        NVARCHAR (50)    NULL,
    [InvoiceNo]      NVARCHAR (50)    NULL,
    [InvoiceDate]    DATE             NULL,
    [ProductionDate] DATE             NULL,
    [Remark]         NVARCHAR (500)   NULL,
    [CreateDate]     DATETIME         NULL,
    [LastDate]       DATETIME         NULL,
    CONSTRAINT [PK_dbo.ProductInfo] PRIMARY KEY CLUSTERED ([Id] ASC),
    CONSTRAINT [FK_dbo.ProductInfo_dbo.Brand_BrandId] FOREIGN KEY ([BrandId]) REFERENCES [dbo].[Brand] ([Id]),
    CONSTRAINT [FK_dbo.ProductInfo_dbo.ProductCategory_CategoryId] FOREIGN KEY ([CategoryId]) REFERENCES [dbo].[ProductCategory] ([Id])
);


GO
CREATE NONCLUSTERED INDEX [IX_BrandId]
    ON [dbo].[ProductInfo]([BrandId] ASC);


GO
CREATE NONCLUSTERED INDEX [IX_CategoryId]
    ON [dbo].[ProductInfo]([CategoryId] ASC);

生成代码:

    /// 
    /// 品牌实体类
    /// 
    [Table("Brand")]
    public partial class Brand 
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
        public Brand()
        {
            ProductInfoes = new HashSet();
        }

        public Guid Id { get; set; }

        [Required]
        [StringLength(50)]
        public string Name { get; set; }

        [Required]
        [StringLength(50)]
        public string Initials { get; set; }

        [StringLength(50)]
        public string Tag { get; set; }

        [StringLength(500)]
        public string Remark { get; set; }

        public DateTime? CreateDate { get; set; }

        public DateTime? LastDate { get; set; }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public virtual ICollection ProductInfoes { get; set; }
    }
 [Table("ProductInfo")]
    public partial class ProductInfo
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
        public ProductInfo()
        {
            Workorders = new HashSet();
        }

        public Guid Id { get; set; }

        /// 
        /// 品牌ID
        /// 
        public Guid? BrandId { get; set; }

        /// 
        /// 产品种类ID
        /// 
        public Guid? CategoryId { get; set; }

        /// 
        /// 型号
        /// 
        [Required]
        [StringLength(50)]
        public string Model { get; set; }

        /// 
        /// 产品序列号
        /// 
        [StringLength(50)]
        public string SN { get; set; }

        /// 
        /// 产品版本
        /// 
        [StringLength(50)]
        public string Version { get; set; }

        /// 
        /// 发票号码[// 先不用了 // 购买商场字段先放到这里,以后创建单独字段]
        /// 
        [StringLength(50)]
        public string InvoiceNo { get; set; }

        /// 
        /// 购买日期
        /// 
        [Column(TypeName = "date")]
        public DateTime? InvoiceDate { get; set; }

        // 忘记写此字段了,暂时先使用Tag字段代替
        //[Display(Name = "购买商场")]
        //public string Shop { get; set; }

        /// 
        /// 生产日期
        /// 
        [Column(TypeName = "date")]
        public DateTime? ProductionDate { get; set; }

        [StringLength(500)]
        public string Remark { get; set; }

        public DateTime? CreateDate { get; set; }

        public DateTime? LastDate { get; set; }

        public virtual Brand Brand { get; set; }

        public virtual ProductCategory ProductCategory { get; set; }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public virtual ICollection Workorders { get; set; }
    }

 

你可能感兴趣的:(Entity,Framework)