dotnet / dotnet/efcore

EFMigration generate scripts with comments

Open
#33,228 2 comments 0 reactions 0 assignees View on GitHub
area-migrations customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

Hello:

I'm using migration command to generate sql script:

```
dotnet ef migrations script --output foo.sql --context FooDbContext
```
genreated script like this:
```
CREATE TABLE [Foos] (
[Id] int NOT NULL IDENTITY,
[Name] nvarchar(max) NOT NULL,
[Description] nvarchar(max) NULL,
[CreateDate] datetime2 NOT NULL,
CONSTRAINT [PK_Foos] PRIMARY KEY ([Id])
);
GO

IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'Id', N'CreateDate', N'Description', N'Name') AND [object_id] = OBJECT_ID(N'[Foos]'))
SET IDENTITY_INSERT [Foos] ON;
INSERT INTO [Foos] ([Id], [CreateDate], [Description], [Name])
VALUES (1, '2024-03-04T16:33:03.1950147+08:00', N'desc1', N'Foo1'),
(2, '2024-03-04T16:33:03.1950159+08:00', N'desc2', N'Foo2');
```
I want to ask you if there is possibility to generate scripts with comments like this?
```
--create Foo Table for Unit Test only
CREATE TABLE [Foos] (
[Id] int NOT NULL IDENTITY,
[Name] nvarchar(max) NOT NULL,
[Description] nvarchar(max) NULL,
[CreateDate] datetime2 NOT NULL,
CONSTRAINT [PK_Foos] PRIMARY KEY ([Id])
);
GO

--insert mock datas
IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'Id', N'CreateDate', N'Description', N'Name') AND [object_id] = OBJECT_ID(N'[Foos]'))
SET IDENTITY_INSERT [Foos] ON;
INSERT INTO [Foos] ([Id], [CreateDate], [Description], [Name])
VALUES (1, '2024-03-04T16:33:03.1950147+08:00', N'desc1', N'Foo1'),
(2, '2024-03-04T16:33:03.1950159+08:00', N'desc2', N'Foo2');
```
Thanks!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.