数据表格式
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);
生成代码:
/// <summary>
/// 品牌实体类
/// </summary>
[Table("Brand")]
public partial class Brand
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Brand()
{
ProductInfoes = new HashSet<ProductInfo>();
}
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<ProductInfo> ProductInfoes { get; set; }
}
[Table("ProductInfo")]
public partial class ProductInfo
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public ProductInfo()
{
Workorders = new HashSet<Workorder>();
}
public Guid Id { get; set; }
/// <summary>
/// 品牌ID
/// </summary>
public Guid? BrandId { get; set; }
/// <summary>
/// 产品种类ID
/// </summary>
public Guid? CategoryId { get; set; }
/// <summary>
/// 型号
/// </summary>
[Required]
[StringLength(50)]
public string Model { get; set; }
/// <summary>
/// 产品序列号
/// </summary>
[StringLength(50)]
public string SN { get; set; }
/// <summary>
/// 产品版本
/// </summary>
[StringLength(50)]
public string Version { get; set; }
/// <summary>
/// 发票号码[// 先不用了 // 购买商场字段先放到这里,以后创建单独字段]
/// </summary>
[StringLength(50)]
public string InvoiceNo { get; set; }
/// <summary>
/// 购买日期
/// </summary>
[Column(TypeName = "date")]
public DateTime? InvoiceDate { get; set; }
// 忘记写此字段了,暂时先使用Tag字段代替
//[Display(Name = "购买商场")]
//public string Shop { get; set; }
/// <summary>
/// 生产日期
/// </summary>
[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<Workorder> Workorders { get; set; }
}