我创建了项目
SqlSharpener,它应该能够做你所要求的.
例如,给定在SSDT项目中定义的这些表:
CREATE TABLE [dbo].[Tasks]
(
[Id] INT NOT NULL PRIMARY KEY IDENTITY,[Name] VARCHAR(50) NOT NULL,[Description] VARCHAR(1000) NOT NULL,[TaskStatusId] INT NOT NULL,[Created] DATETIME NOT NULL,[CreatedBy] VARCHAR(50) NOT NULL,[Updated] DATETIME NOT NULL,[UpdatedBy] VARCHAR(50) NOT NULL,CONSTRAINT [FK_Tasks_ToTaskStatus] FOREIGN KEY ([TaskStatusId]) REFERENCES [TaskStatus]([Id])
)
CREATE TABLE [dbo].[TaskStatus]
(
[Id] INT NOT NULL PRIMARY KEY,[Name] VARCHAR(50) NOT NULL
)
您可以创建一个将生成实体的T4模板:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
namespace SimpleExample.EntityFrameworkCodeFirst
{
public partial class TaskContext : DbContext
{
public TaskContext(): base()
{
}
public DbSet Tasks { get; set; }
public DbSet TaskStatus { get; set; }
}
[Table("Tasks")]
public partial class Tasks
{
[Key]
[required]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Int32? Id { get; set; }
[required]
[MaxLength(50)]
public String Name { get; set; }
[required]
[MaxLength(1000)]
public String Description { get; set; }
[required]
public Int32? TaskStatusId { get; set; }
[ForeignKey("Id")]
public virtual TaskStatus TaskStatus { get; set; }
[required]
public DateTime? Created { get; set; }
[required]
[MaxLength(50)]
public String CreatedBy { get; set; }
[required]
public DateTime? Updated { get; set; }
[required]
[MaxLength(50)]
public String UpdatedBy { get; set; }
}
[Table("TaskStatus")]
public partial class TaskStatus
{
[Key]
[required]
public Int32? Id { get; set; }
public virtual ICollection Tasks { get; set; }
[required]
[MaxLength(50)]
public String Name { get; set; }
}
}