efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Using HasData with new lines breaks the migrations

Open shawnwildermuth opened this issue 8 years ago • 10 comments

Describe what is not working as expected. I create a HasData that has a new line in it, and the corresponding HasData doesn't deal with new lines, Need to add @"" to make it work.

Steps to reproduce

  1. Add HasData with a new line:
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
      base.OnModelCreating(modelBuilder);

      modelBuilder.Entity<Product>()
        .HasData(new Product()
        {
          Id = 1,
          Title = "Temp",
          ArtDescription = @"In Rembrandt’s time, peacocks were a delicacy for the well-to-do: the meat was used as filling for pasties. After being slaughtered, the birds were hung upside down to drain their blood, as Rembrandt has depicted
                in this pantry. He must have been fascinated by the plumage’s magnificent markings and dazzling colours:
                blue, green and yellow ochre."
        });
    }
  1. Do "dotnet ef migrations add Seeding"
  2. Compile project and fails because of new lines in generated code.

Further technical details

EF Core version: 2.1.1 Database Provider: Microsoft.EntityFrameworkCore.SqlServer Operating system: Win10 Pro IDE: (e.g. Visual Studio 2017 15.7)

shawnwildermuth avatar Jul 03 '18 22:07 shawnwildermuth

@shawnwildermuth What generated code does the "dotnet ef migrations add Seeding" command generate? I was a bit confused... are you saying that doing @"" solves the problem? As a workaround, I recommend using FluentMigrator.

@ajcvickers I feel you should push customers harder on submitting complete repros. How much time does Microsoft waste even building test repros for this stuff?

jzabroski avatar Jul 05 '18 19:07 jzabroski

@jzabroski In cases where it looks pretty clear what the issue is without a repro we tend not to ask. This is one such case. That is, I haven't attempted to repro it, but it seems pretty clear why it would happen and that it is a bug.

In general, we need to strike a balance between spending time investigating and being too dogmatic about issues such that people don't feel like reporting them, since that would also be bad for us. The key is always whether or not we can understand and reproduce what is going on. If we can, then good. If not, then we ask for more info.

ajcvickers avatar Jul 05 '18 19:07 ajcvickers

@AndriySvyryd I was not able to find the dupe for this.

ajcvickers avatar Jul 06 '18 20:07 ajcvickers

Then it's not a dupe

AndriySvyryd avatar Jul 06 '18 20:07 AndriySvyryd

Sorry I missed this. The Github notifications app is down on my phone. I can give you a repro if you like.

shawnwildermuth avatar Jul 10 '18 22:07 shawnwildermuth

If you do, I'll take a stab at fixing it.

On Tue, Jul 10, 2018 at 6:51 PM, Shawn Wildermuth [email protected] wrote:

Sorry I missed this. The Github notifications app is down on my phone. I can give you a repro if you like.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/aspnet/EntityFrameworkCore/issues/12542#issuecomment-403990748, or mute the thread https://github.com/notifications/unsubscribe-auth/AAbT_c-Xn1EB5bR-2WZ7nKlwtbdmqpWuks5uFTAEgaJpZM4VBsGn .

jzabroski avatar Jul 11 '18 01:07 jzabroski

Ok, the real problem with is newline only (not /r/n but just /n as in my case with a Json file from a non-windows line ending). Here is a repro case:

https://github.com/shawnwildermuth/NewLineHasDataMigrationIssue

shawnwildermuth avatar Jul 11 '18 19:07 shawnwildermuth

@jzabroski Update this line. 😉

bricelam avatar Jul 11 '18 22:07 bricelam

Is it fixed ?

UsamaKhalil-KSO avatar May 31 '20 12:05 UsamaKhalil-KSO

@usamakhalil86 Yes, in 2.2.0 If you are still experiencing it open a new issue with a small repro project

AndriySvyryd avatar May 31 '20 18:05 AndriySvyryd