Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply column comments when creating tables #16750

Merged
merged 1 commit into from
Jul 26, 2019

Conversation

roji
Copy link
Member

@roji roji commented Jul 25, 2019

In our current comment support (#15037), when creating a table only the table's comment is applied, and not the table's columns' comments.

@roji roji force-pushed the ColumnCommentsWhenCreatingTable branch from c31ec2a to 1fd4a5a Compare July 25, 2019 21:11
@roji roji force-pushed the ColumnCommentsWhenCreatingTable branch from 1fd4a5a to 17b5997 Compare July 25, 2019 21:12
@roji roji merged commit a02785c into master Jul 26, 2019
@ghost ghost deleted the ColumnCommentsWhenCreatingTable branch July 26, 2019 15:50
@dazbradbury
Copy link

Can I confirm this is working as expected when it comes to using dotnet ef scaffold in an initial DB -> EF Core model build (or DB-first approach)?

For example, if we had a table such as:

CREATE TABLE [dbo].[Test] (
    [Setting] NVARCHAR (MAX) NOT NULL,
);

GO
EXEC sp_addextendedproperty @name = N'MS_Description',
    @value = N'This is a test',
    @level0type = N'SCHEMA',
    @level0name = N'dbo',
    @level1type = N'TABLE',
    @level1name = N'Admin',
    @level2type = N'COLUMN',
    @level2name = N'Setting'

It seems to produce into the DBContext:

entity.Property(e => e.Setting)
                    .IsRequired()
                    .HasComment("This is a test");

However, I was expecting this comment to be translated to a c# comment in the model also, but it remains as:

public partial class Test
    {
        [ConcurrencyCheck] public string Setting { get; set; }
    }

Should I be seeing / is there a way for the scaffold to build:

public partial class Test
    {
        /// <summary>
        /// This is a test
        /// </summary>
        [ConcurrencyCheck] public string Setting { get; set; }
    }

@ErikEJ
Copy link
Contributor

ErikEJ commented Jul 24, 2020

@dazbradbury No, you cannot. But latest daily build of EF Core Power Tools generates XML comments

@dazbradbury
Copy link

dazbradbury commented Jul 24, 2020

@ErikEJ - Ah very cool! That's exactly what I'm after. Just had a quick play (v. 2.4.122) and it seems to work perfectly.

Unfortunately we already have a batch script in place to re-build our model (which is used in various places from the command line and thus hard to switch to your extension). Do you mind sharing the pertinent code that does this?

Assuming it's layered as a subsequent call to the standard dotnet ef scaffold perhaps we could cherry pick that specific, and very helpful, bit of code.

@ErikEJ
Copy link
Contributor

ErikEJ commented Jul 28, 2020

@dazbradbury It is a bit hairy, as you need to pull in a lot of internal code: https://github.com/ErikEJ/EFCorePowerTools/blob/master/src/GUI/RevEng.Core/CommentCSharpEntityTypeGenerator.cs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants