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

Reverse engineering: Scaffold-DbContext creates invalid code for default constraints with line breaks #8077

Closed
reader-man opened this issue Apr 5, 2017 · 3 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@reader-man
Copy link

Describe what is not working as expected.
When running Scaffold-DbContext
The Generation of Fluent API for the default value in Context.OnModelCreating(ModelBuilder modelBuilder), returns SQL Server comments which affects the compilation of the Project in VS.

If you are seeing an exception, include the full exceptions details (message and stack trace).

Compilation Error in intellisense.

Steps to reproduce

make a new database in sql server, and run the file "sqlSampleTableToProveGenerationProblem.sql" and don't delete the first empty lines:

https://goo.gl/w1Fb5v

then generate the POCO Entities + the Context, and you will see these problematic lines:

                entity.Property(e => e.AnythingCol)
                    .HasColumnName("anythingCol")
                    .HasColumnType("TypeBoolean_Dom")
                    .HasDefaultValueSql("


/*==============================================================*/
/* Default: D_0                                                 */
/*==============================================================*/
create default D_0
    as 0
");
            });

Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.

<code listing>

Further technical details

EF Core version: 1.1
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Win 10
IDE: Visual Studio 2017

@bricelam
Copy link
Contributor

bricelam commented Apr 5, 2017

Note to fixer, Migrations handles this by generating verbatim string literals for multi-line strings.

@jnegron357
Copy link

jnegron357 commented Apr 10, 2017

I'm getting the same issue except my output is just a bunch of empty lines:
`.HasDefaultValueSql("create default [DEFgetdate] as getdate()

");`
When I look at the definition for the custom default DEFgetdate I see that it also has several lines of empty space, could it be the EF core is picking it up from there? If so then maybe it just needs a Trim() function call at the time of generation of code.

We are using Sql Server 2008 R2 (SP2) - 10.50.4042.0 (X64)

EF Core version: 1.1.1
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Win 7
IDE: Visual Studio Professional 2017
Version 15.1 (26403.0) Release

@lajones
Copy link
Contributor

lajones commented Apr 13, 2017

Fixed by PR #8145. Note: we are just making sure the C# works here, we are not getting into trimming just yet. For now I'd rather just report exactly what SQL Server has stored rather than interpret it in any way. That may change as there's another bug, #7918, where the default value wasn't right because we weren't correctly counting the open and close parentheses that SQL Server had stored in the default value. When we address that we can think about whether to trim at the same time. On the other hand we may choose not to change it so that round tripping (DB -> Scaffolding -> updating DB via Migrations) works.

@lajones lajones closed this as completed Apr 13, 2017
@lajones lajones added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Apr 13, 2017
@ajcvickers ajcvickers changed the title Scaffold-DbContext with create default Reverse engineering: Scaffold-DbContext creates invalid code for default constraints with line breaks May 9, 2017
@divega divega added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. labels May 10, 2017
@ajcvickers ajcvickers modified the milestones: 2.0.0-preview1, 2.0.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

6 participants